Construct the following SQL statement in the student table- SELECT statement using ORDER BY clause.
Advertisements
Question
Construct the following SQL statement in the student table-
SELECT statement using ORDER BY clause.
Advertisements
Solution
ORDER BY clause
The ORDER BY clause in SQL is used to sort the data in either ascending or descending based on one or more columns.
1. By default ORDER BY sorts the data in ascending order.
2. We can use the keyword DESC to sort the data in descending order and the keyword ASC to sort in ascending order.
The ORDER BY clause is used as:
SELECT <column-name> [,<column-name>,….] FROM <table-name> ORDER
BY <column1>,<column2>, …ASC\ DESC;
For example :
To display the students in alphabetical order of their names, the command is used as
SELECT * FROM Student ORDER BY Name;
The above student table is arranged as follows :
| Admno | Name | Gender | Age | Place |
| 104 | Abinandh | M | 18 | Chennai |
| 101 | Adarsh | M | 18 | Delhi |
| 102 | Akshith | M | 17 | Bangalore |
| 100 | Ashish | M | 17 | Chennai |
| 103 | Ayush | M | 18 | Delhi |
| 106 | Devika | F | 19 | Bangalore |
| 107 | Hema | F | 17 | Chennai |
| 105 | Revathi | F | 19 | Chennai |
APPEARS IN
RELATED QUESTIONS
The command to delete a table is ______
The clause used to sort data in a database.
Differentiate Unique and Primary Key constraint.
Which component of SQL lets inserts values in tables and which lets to create a table?
Write any three DDL commands.
Write the use of the Savepoint command with an example.
Write the different types of constraints and their functions.
Consider the following employee table. Write SQL commands for the question.
| EMP CODE | NAME | DESIG | PAY | ALLO WANCE |
| S1001 | Hariharan | Supervisor | 29000 | 12000 |
| P1002 | Shaji | Operator | 10000 | 5500 |
| P1003 | Prasad | Operator | 12000 | 6500 |
| C1004 | Manjima | Clerk | 8000 | 4500 |
| M1005 | Ratheesh | Mechanic | 20000 | 7000 |
To display the details of all employees who are operators.
What are the components of SQL? Write the commands in each.
Construct the following SQL statement in the student table-
SELECT statement using GROUP BY clause.
