The most commonly used SQL command is SELECT statement. SQL SELECT statement is used to query or retrieve data from a table in the database. A query may retrieve information from specified columns or from all of the columns in the table. To create a simple SQL SELECT Statement, you must specify the column(s) name and the table name. The whole query is called SQL SELECT Statement.
Syntax :
SELECT {* |selected_coulumns}
FROM {table_name}
[WHERE condition]
[GROUP BY condition_list]
[HAVING condition]
[ORDER BY {column_name1,column_name2,...,column_nameN [ ASC | DESC ] };
Note : here '|' means OR.
In above SELECT query,
SELECT and FROM are compulsory words where as WHERE,GROUP BY,HAVING AND ORDER BY are optionals.
DISTINCT is used for eliminate duplicates and display only the unique results in the query output.
ALL is for select/display all the columns of table.
ASC - sort data in ASCENDING order
DESC - sort data in DESCENDING order
Example :
Assume we have table named Student which contain student's id(sid),name and age.
SELECT * FROM student;
SELECT sid,name FROM student;
SELECT * FROM student where age>20;
Here,First query display all the data of student table where as second one display only student's id and name of all students.Last query display only those data whose age is greater than 20.

