"Union all" and "UNION" ???? Return the same result or not ??

From: KENNY L. CHEN <kenny_60559_at_yahoo.com>
Date: 23 Jan 2004 02:34:10 -0800
Message-ID: <83f59352.0401230234.210b7b56_at_posting.google.com>


Dear experts,

I have two tables in my Oracle 8i database: TEST (COL1,COl2,REC_NO) and TEST1 (COL1,COL2,REC_NO).

Both tables are unique-indexed on (COL1,COL2,REC_NO).

I think the following SQL commands will return the same result but one of my friends don't think so. He said "QUERY 1" will return 1 unsorted record (ROWNUM < 2 ) first then sort the result (ORDER BY COL1 ASC, COL2 ASC, REC_NO ASC).
In "QUERY 2" , "UNION" will sort first then return the first distincted record.
But I can't duplicate the situation he said.

AM I WRONG ??? Please advise and thank you.

KENNY CHEN

  • QUERY 1 ============= ( SELECT COL1 , COL2 ,REC_NO FROM TEST UNION ALL SELECT COL1 , COL2 ,REC_NO FROM TMP_TEST ) WHERE (COL1 = :val1 AND COL2 = :val2 AND REC_NO > :val3 ) AND ROWNUM < 2 ORDER BY COL1 ASC, COL2 ASC, REC_NO ASC
  • QUERY 2 ============= (SELECT COL1 , COL2 ,REC_NO FROM TEST UNION SELECT COL1 , COL2 ,REC_NO FROM TMP_TEST ) WHERE (COL1 = :val1 AND COL2 = :val2 AND REC_NO > :val3 ) AND ROWNUM < 2 ORDER BY COL1 ASC, COL2 ASC, REC_NO ASC
Received on Fri Jan 23 2004 - 11:34:10 CET

Original text of this message