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 > Database Server Software > MySQL > 2 Order By's with 3 unions

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-25-05, 16:45
PolarBear2k PolarBear2k is offline
Registered User
 
Join Date: Jun 2005
Posts: 79
2 Order By's with 3 unions

Hi,

I have a query with 3 unions and I want to order the first two unions using one ORDER BY and the last union with a different ORDER BY. Unfortunately I am unable to group the first two selects with the first ORDER BY with parentheses without getting an error.

ex:

(SELECT a,b FROM table1)
UNION
(SELECT c,d FROM table2)
ORDER BY a,d
UNION
SELECT x,y FROM table3
ORDER BY y


Thanks
Reply With Quote
  #2 (permalink)  
Old 11-25-05, 17:29
jfulton jfulton is offline
Registered User
 
Join Date: Apr 2005
Location: Baltimore, MD
Posts: 297
Try this. You need the "LIMIT" statement in there.
Code:
(
   SELECT * 
   FROM
   (
      (SELECT a,b FROM table1)
      UNION
      (SELECT c,d FROM table2)
   ) AS blah
   ORDER BY a,d
   LIMIT n
)
UNION ALL
(
   SELECT x,y FROM table3
   ORDER BY y
   LIMIT n
)
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