- Select command is used to fetch records from the database table and display on the screen.
SELECT * FROM student;
- It will display all the records from all the columns.
Accessing records for the particular column
SELECT <column_list>FROM <table_name>;
SELECT eCode, eName FROM EMPLOYEE;
- A WHERE clause can be used to access records base on some specific condition.
- It will display only those records that satisfy given condition.
- Searching will be perform on the column which is specified in the WHERE clause.
- We can use relational operators with the WHERE clause such as =,! =, >, < and so on.
- We can also specify logical operator to combine multiple conditions such as AND, and OR.
SELECT * FROM <table_name> WHERE <expr>;
SELECT * FROM student WHERE std_name=’ABC’; SELECT * FROM student WHERE std_name=’ABC’ AND std_no=1; SELECT * FROM student WHERE std_name=’ABC’OR city=’Rajkot’;
- A DISTINCT clause is used to display only unique rows from the database table
SELECT DISTINCT * FROM <table_name>;
SELECT DISTINCT * FROM student; SELECT DISTINCT city FROM student;
- ORDER BY clause is used to display records in a sorted manner.
- Select command display record in the manner in which they are inserted.
- We can perform sorting on the records by using ORDER BY clause with select command
- It is possible to apply sorting either on single column or on multiple column by separating column name with coma (,) sign.
- When sorting is performing on multiple columns specified in the ORDER BY clause, it will sort on the second column if and only if it founds duplicate record in the 1st
- A sorting can be performed either in ascending or in descending order.
- When no order is specified the record will be sort in ascending mode which is the default order.
- To sort record in descending order we can specify DESC as the sorting order after the column name.
- When records are sort on ascending order it will sort in A to Z and 0 to 9 orders.
- If record is descending then it will display records in Z to A and 9 to 0 order.
SELECT * FROM<table name> ORDER BY <column list> [order]; SELECT * FROM<table name> WHERE <condition> ORDER BY <column list> [order];
SELECT * FROM student ORDER BY std_name; SELECT * FROM student WHERE std_name != ’ABC’ ORDER BY city DESC;