Download presentation
Presentation is loading. Please wait.
Published byEdwin Cannon Modified over 5 years ago
1
‘ORDER BY’ Order by clause allows sorting of query results by one or more columns. Sorting can be done in ascending or descending. Default order is ascending. Syntax Select <attribute list separated with comma> from <table name> where <condition> order by <attribute> <asc/desc>
2
WAQ to display the details of employees in the ascending order of name
‘ORDER BY’ ID NAME place 1 ARUN Dubai 2 VARUN Sharjah 3 ALI 4 GEORGE Ajman 5 MOHD Al ain WAQ to display the details of employees in the ascending order of name output Select * from employee order by name ; ID NAME place 3 ALI Dubai 1 ARUN 4 GEORGE Ajman 5 MOHD Al ain 2 VARUN Sharjah
3
Select * from student where name like ‘A%’ order by mark desc ;
ID NAME Mark 1 ARUN 45 2 VARUN 67 3 ALI 75 4 GEORGE 70 5 MOHD 90 WAQ to display the details of students whose name starting with ‘A’ in the descending order of mark. output ID NAME Mark 3 ALI 75 1 ARUN 45 Select * from student where name like ‘A%’ order by mark desc ;
4
Select * from student order by mark desc, name asc ;
ID NAME Mark 1 ARUN 45 2 VARUN 55 3 ALI 4 GEORGE 70 5 MOHD 90 WAQ to display the details of students in the the descending order of mark and then ascending order of name output ID NAME Mark 5 MOHD 90 4 GEORGE 70 3 ALI 55 2 VARUN 1 ARUN 45 Select * from student order by mark desc, name asc ;
5
or Arithmetic Operations
WAQ to display the sum of the numbers 5 and 4. Select 5+4 from dual; or Select 5+4; Dual is a small worktable with one row and one column.
6
WAQ to display id,name,total marks of students
arithmetic operations WAQ to display id,name,total marks of students student output ID NAME Mark mark2 1 ARUN 45 50 2 VARUN 55 3 ALI 85 80 4 GEORGE 70 ID NAME Mark1+Mark2 1 ARUN 95 2 VARUN 105 3 ALI 165 4 GEORGE Select id,name,mark1+mark2 from student;
7
Alias name is another name given to an attribute
8
WAQ to display id,name,total marks of students
SQL – arithmetic operations & Alias name WAQ to display id,name,total marks of students output student ID NAME Mark Mark2 1 ARUN 45 50 2 VARUN 55 3 ALI 85 80 4 GEORGE 70 ID NAME total 1 ARUN 95 2 VARUN 105 3 ALI 165 4 GEORGE Select id,name,mark1+mark2 as “total” from student;
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.