This week's book giveaways are in the Refactoring and Agile forums.We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!

# Is the answer correct?

Sona Patel
Ranch Hand
Posts: 75
Hi...
I am reading about using 'order by' clause. I came across following question -

The results from an SQL query are shown here.

Which of the following SQL statements could not have produced this output?

A. select deptno,dname,loc from dept order by 2 asc, 1 asc, 3 desc;
B. select deptno,dname,loc from dept order by 3 asc;
C. select deptno,dname,loc from dept order by 2 asc;
D. select deptno,dname,loc from dept order by 2 asc, 3 asc, 1 desc;

I think correct ans is (B.). But book says it is (C.). What do you think?

Jan Cumps
Bartender
Posts: 2584
11
Hi Sona,

If you put an exam question on the Ranch, you have to tell where you got the question from.

Sona Patel
Ranch Hand
Posts: 75
Its from OCP introduction to oracle 9i by Jason Couchman...

Fatih Keles
Ranch Hand
Posts: 182
Hi Sona,

I agree with you, and also my local 11g r1 database does.

Regards,

Fatih.

Sona Patel
Ranch Hand
Posts: 75
Hey Fatih...

Thanks...
How ignorant of me...i forgot i can try it out. thanks for reminding me

Regards,

Eric Pascarello
author
Rancher
Posts: 15385
6

swapnil kachave
Greenhorn
Posts: 27
order by 2 asc means it doing order by dname in ascending order.
if you check the alphabetic order of colom 2 you will find the answer c is right.
if you are saying the answer is (b) then check the order by statement which say order by LOC in ascending order. which is not in alphabeticall order so that answer (c) is right.

Sona Patel
Ranch Hand
Posts: 75
Hi Swapnil...

Option (A),(C),(D) will produce the output as shown in the question.
Option (B) will not produce the same output right ??

Question is :
Which of the following SQL statements could not have produced this output?

So the ans is (B) could not have produced the same out put.

swapnil kachave
Greenhorn
Posts: 27
Sona Patel wrote:Hi Swapnil...

Option (A),(C),(D) will produce the output as shown in the question.
Option (B) will not produce the same output right ??

Question is :
Which of the following SQL statements could not have produced this output?

So the ans is (B) could not have produced the same out put.

Yes..
If you go for b then check the order by clouse where you specify the different column no and output not contain that column in sorted oreder

Vinod Tiwari
Ranch Hand
Posts: 466
1
Correct answer is C only.

A<O><R><S (alphabetical order) <br /> <br /> >