• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 310
  • Last Modified:

MySQL syntax

I have two tables with identical structure. For a report, I want to select data from both, based on dates.

So I tried this: SELECT * FROM `resva` WHERE date > '2012-06-15', * from resv where date < '2012-07-30'

It fails.

What is the proper syntax?

Thanks
0
Richard Korts
Asked:
Richard Korts
  • 3
  • 2
1 Solution
 
Gerry BartleySoftware EngineerCommented:
SELECT * FROM `resva` WHERE date > '2012-06-15'
UNION
SELECT * FROM `resv` WHERE date > '2012-07-30'
0
 
Richard KortsAuthor Commented:
To gbartley

That works great. I didn't mention it but I want to order by one (or several) columns. I tried the following & it failed. How do I add "order by"?

SELECT * FROM `resva` WHERE date > '2012-06-15' order by pickup
UNION
SELECT * FROM `resv` WHERE date < '2012-07-17' order by pickup

Thanks
0
 
Gerry BartleySoftware EngineerCommented:
Try brackets

(SELECT * FROM `resva` WHERE date > '2012-06-15' order by pickup)
UNION
(SELECT * FROM `resv` WHERE date < '2012-07-17' order by pickup)
0
 
Gerry BartleySoftware EngineerCommented:
Better to order the final result

(SELECT * FROM `resva` WHERE date > '2012-06-15')
UNION
(SELECT * FROM `resv` WHERE date < '2012-07-17' )
ORDER BY pickup
0
 
Richard KortsAuthor Commented:
Excellent and works fast too,

Thanks
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now