Doing calculation using SELECT CLAUSE
select 1+2;
Calling function on SELECT clause e.g. displaying current date
select now();
SELECT data from one row till another row like Paging
select * from Stock order by COMPANY LIMIT 0,2;
Selecting data from result of another query by using derived table.
select RIC from (select s.RIC, m.NAME from Stock s, Market m where s.LISTED_ON_EXCHANGE=m.RIC) t where RIC > 'G'
1) Most often we use SELECT Operator with WHERE Clause, try to use column which has index on WHERE clause. Using a non index column on WHERE clause can slow your query drastically and effect would be more visible when your table data increases.
2) If you don't need all columns, don’t use * wild card. SELECT query with few columns are slightly faster than all columns.
You can introduce new columns in result set of SELECT Query by using keyword "AS"
5) Always use IS NULL or NULL for including or excluding values which could be null. Don’t use 'null' that will be treated as text.
6) While writing SQL query not just SELECT, its good practice to write keyword in small case and TABLES and COLUMNS in capital.
Read full article from 10 Example Queries of SQL Select Command
select 1+2;
Calling function on SELECT clause e.g. displaying current date
select now();
SELECT data from one row till another row like Paging
select * from Stock order by COMPANY LIMIT 0,2;
Selecting data from result of another query by using derived table.
select RIC from (select s.RIC, m.NAME from Stock s, Market m where s.LISTED_ON_EXCHANGE=m.RIC) t where RIC > 'G'
1) Most often we use SELECT Operator with WHERE Clause, try to use column which has index on WHERE clause. Using a non index column on WHERE clause can slow your query drastically and effect would be more visible when your table data increases.
2) If you don't need all columns, don’t use * wild card. SELECT query with few columns are slightly faster than all columns.
You can introduce new columns in result set of SELECT Query by using keyword "AS"
5) Always use IS NULL or NULL for including or excluding values which could be null. Don’t use 'null' that will be treated as text.
6) While writing SQL query not just SELECT, its good practice to write keyword in small case and TABLES and COLUMNS in capital.
Read full article from 10 Example Queries of SQL Select Command
No comments:
Post a Comment