Results 1 to 2 of 2

Thread: Order By

  1. #1
    Join Date
    Jul 2003
    Posts
    18

    Unanswered: 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

  2. #2
    Join Date
    Sep 2002
    Location
    UK
    Posts
    5,171
    Provided Answers: 1

    Re: Order By

    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.)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •