I'm doing a union of two different tables and ordering by the date column. Shouldn't the union make the two date columns one? It's giving me the error: #1052 - Column 'date' in order clause is ambiguous
Am I missing something here? Here's the query:
SELECT comments.*, postid, prayers.date AS date, prayers.type AS type
FROM comments
LEFT JOIN prayers USING (postid)
WHERE comments.username = 'hoodleehoo'
AND comments.new = 1
AND comments.first = 1
AND (comments.type = 'prayer' or comments.type = 'answer')
AND prayers.privacy != 'hidden'
UNION
SELECT comments.*, postid, posts.date AS date, comments.type AS type
FROM comments
LEFT JOIN posts USING (postid)
WHERE comments.username = 'hoodleehoo'
AND comments.new = 1
AND comments.first = 1
AND (comments.type = 'post' or comments.type = 'shared')
ORDER BY date
UPDATE:
I guess you can't use "date". That must be a reserved word. I changed date to "date2" and it's working fine. I'm sure I'm not the only one who will run into this!