Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Is the answer correct?

 
Sona Patel
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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: 2588
11
C++ Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Its from OCP introduction to oracle 9i by Jason Couchman...
 
Fatih Keles
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sona,

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

Regards,

Fatih.
 
Sona Patel
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
IntelliJ IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Correct answer is C only.

A<O><R><S (alphabetical order) <br /> <br /> >
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic