If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > Order By

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-03-03, 05:39
Linirlan Linirlan is offline
Registered User
 
Join Date: Jul 2003
Posts: 18
Order By

Hi,
I'm trying to understand a particular behaviour of ORDER BY.

Suppose I have 3 tables with a similar column name "samecol".

When I execute something like :

SELECT Tab1.a, Tab2.b, Tab3.c
FROM Tab1, Tab2, Tab3
ORDER BY samecol

Surprisingly, without specifying if it must order by Tab1.samecol or Tab2.samecol for instance, the query returns me a recordset.

Do you know if it chooses a table by default ?
Or it randomly order my datas ?

Thanks
Reply With Quote
  #2 (permalink)  
Old 09-03-03, 05:53
andrewst andrewst is offline
Moderator.
 
Join Date: Sep 2002
Location: UK
Posts: 5,171
Re: Order By

Quote:
Originally posted by Linirlan
Hi,
I'm trying to understand a particular behaviour of ORDER BY.

Suppose I have 3 tables with a similar column name "samecol".

When I execute something like :

SELECT Tab1.a, Tab2.b, Tab3.c
FROM Tab1, Tab2, Tab3
ORDER BY samecol

Surprisingly, without specifying if it must order by Tab1.samecol or Tab2.samecol for instance, the query returns me a recordset.

Do you know if it chooses a table by default ?
Or it randomly order my datas ?

Thanks
The answer is DBMS-specific. For example, the above is not possible in Oracle:

SQL> select emp.ename, dept.dname
2 from emp, dept
3 order by deptno;
order by deptno
*
ERROR at line 3:
ORA-00918: column ambiguously defined

(Both tables have a column called deptno.)
__________________
Tony Andrews
http://tinyurl.com/tonyandrews
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On