-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathOrder by.sql
More file actions
34 lines (27 loc) · 928 Bytes
/
Order by.sql
File metadata and controls
34 lines (27 loc) · 928 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
create table student(
name varchar(50),
age int);
insert into student values('Gopi',25);
insert into student values('Gopi',26);
insert into student values('Gopi',24);
insert into student values('Sandhiya',23);
--Order by clause sorts/orders the result set from the select clause based on condition by desc or asc
--Defalut order by clause is asc
select name , age
from student
order by name desc;
--We can sort the result set based on multiple columns in different orders
--In the below queries result are first sorted based on name in the based on mentioned order
--if there is multiple age values for the same name value it will sort the age in the mentioned order for that specific name
select name , age
from student
order by name desc,age asc;
select name , age
from student
order by name ,age desc;
select name , age
from student
order by name ,age ;
select name , age
from student
order by name desc,age desc;