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
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

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
Avatar of Richard Korts
Richard Korts
Flag of United States of America image

ASKER

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
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
What Dave said...

Change to:
SELECT * from wot_head
UNION
SELECT * from wo_head
order by date desc
Avatar of Richard Korts
Richard Korts
Flag of United States of America image

ASKER

Thanks, Dave.
MySQL Server
MySQL Server

MySQL is an open source, relational database management system that runs as a server providing multi-user access to a number of databases. Acquired by Oracle in 2009, it is frequently used in combination with PHP installations, powering most of the WordPress installations.

49K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo