Jump to content

order rows of union query


dadamssg87

Recommended Posts

i have this query and i'm trying to order all of the results by `created` ascending. I've tried putting the later query before the first but the single row from the first query(the way it is right now) gets stuck as the last row in the results. How can i order the results of both queries?

 

(
SELECT * 
FROM Account_activity
WHERE DATE( created ) <  '2011-08-01'
AND username =  '40'
ORDER BY created DESC 
LIMIT 1
)
UNION (
SELECT * 
FROM Account_activity
WHERE MONTH( created ) =  '08'
AND YEAR( created ) =  '2011'
AND username =  '40'
ORDER BY created ASC
)

Link to comment
https://forums.phpfreaks.com/topic/245383-order-rows-of-union-query/
Share on other sites

wow..easy solution

 

(
SELECT * 
FROM Account_activity
WHERE DATE( created ) <  '2011-08-01'
AND username =  '40'
ORDER BY created DESC 
LIMIT 1
)
UNION (
SELECT * 
FROM Account_activity
WHERE MONTH( created ) =  '08'
AND YEAR( created ) =  '2011'
AND username =  '40'
ORDER BY created ASC
)

ORDER BY created ASC

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.