Avatar of Richard Korts
Richard KortsFlag for United States of America asked on

MySQL Query

What is wrong with this:

(SELECT * from wot_head order by date desc) UNION (SELECT * from wo_head order by date desc)

It returns the right result but they are NOT ordered by the column date.

Both tables have identical columns, both have a column named date
MySQL Server

Avatar of undefined
Last Comment
Richard Korts

8/22/2022 - Mon
Dave Baldwin

I don't see that you are ordering the complete results, just the two different ones that you are JOINing. Maybe try..

(SELECT * from wot_head) UNION (SELECT * from wo_head )  ORDER BY date desc
ASKER
Richard Korts

To DaveBaldwin

There is an order by clause after BOTH selects. It's not capitalized, does that matter?

Or is MySQL confused because there are two date columns? Do I have to specify which date field in which table (ie, order by wot_head.date)?

Oh maybe I have to put the order by AFTER the UNION business?
ASKER CERTIFIED SOLUTION
Dave Baldwin

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Lawrence Barnes

What Dave said...

Change to:
SELECT * from wot_head
UNION
SELECT * from wo_head
order by date desc
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
ASKER
Richard Korts

Thanks, Dave.