MySQL Forums
Forum List  »  InnoDB

ORDER BY ignored in UNION
Posted by: jason nevin
Date: March 15, 2007 03:19AM

Hi

I have a UNION statement where I only want to sort the second dataset. It seems that the ORDER BY in the statement below is ignored. When I take away the brackets it sorts the whole UNIONed dataset as you would expect.

Any suggestions as to how I can get my results out?

SELECT MAX(ContactID) + 1 AS ContactID,
'Please select a customer ...' AS CustomerName
FROM tblcustomer
UNION ALL
( SELECT ContactID,
Name as CustomerName
FROM tblcustomer
WHERE ManagerID = 1
order by CustomerName )



Edited 1 time(s). Last edit at 03/15/2007 03:20AM by jason nevin.

Options: ReplyQuote


Subject
Views
Written By
Posted
ORDER BY ignored in UNION
19794
March 15, 2007 03:19AM
8899
March 15, 2007 05:19PM
7904
March 16, 2007 05:49AM
7724
March 19, 2007 11:27AM
6933
January 06, 2009 09:31PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.