INTERVIEW QUESTIONS
ORACLE
PL-SQL
DETAILS
Question: How to sort the rows in SQL?
Answer: Sort the Rows: SELECT column1, column2, ... FROM table_name ORDER BY columnX, columnY, .. SELECT column1, column2, ... FROM table_name ORDER BY columnX DESC SELECT column1, column2, ... FROM table_name ORDER BY columnX DESC, columnY ASC
|
Question:
How to sort the rows in SQL?
Answer:
Sort the Rows: SELECT column1, column2, ... FROM table_name ORDER BY columnX, columnY, .. SELECT column1, column2, ... FROM table_name ORDER BY columnX DESC SELECT column1, column2, ... FROM table_name ORDER BY columnX DESC, columnY ASC Source: CoolInterview.com
1. select column1,column2,column3 from table1 where column1>10 order by 1,3,2;
Inthis case it sorts based on the columns' position in the select query i.e. in the above query it will sort first based on column1 then on column3 and then by column2. By default the sort is in ascending order, if you want it to be in descending order, you need to specify the key word DESC in ORDER BY clause. 2. select * from emp order by eno desc; You can sort your results based on any column in the tables because you are select all the columns. 3.select eno,ename from emp order by deptno; This is wrong because the column deptno is not present in the select clause. Source: CoolInterview.com
Answered by: Lalitha | Date: 8/12/2010
| Contact Lalitha
If you have the better answer, then send it to us. We will display your answer after the approval.
Rules to Post Answers in CoolInterview.com:-
- There should not be any Spelling Mistakes.
- There should not be any Gramatical Errors.
- Answers must not contain any bad words.
- Answers should not be the repeat of same answer, already approved.
- Answer should be complete in itself.
|