开发者

Get information from multiple identical mysql tables

Lets say i have 4 identical tables: table1, table2, table3, table4

All table have same structure: id total开发者_StackOverflow date

I want to get all information from all tables using same condition. I mean merge 4 sql requests in 1

So instead of having these 4 sql, have just one. Remember, same condition for all tables, in our case date = 2011-06-23

SELECT * FROM table1 where date = '2011-06-23'
SELECT * FROM table2 where date = '2011-06-23'
SELECT * FROM table3 where date = '2011-06-23'
SELECT * FROM table4 where date = '2011-06-23'

Thank you for your time.


(SELECT * FROM table1 where date = '2011-06-23')
UNION
(SELECT * FROM table2 where date = '2011-06-23')
UNION    
(SELECT * FROM table3 where date = '2011-06-23')
UNION    
(SELECT * FROM table4 where date = '2011-06-23')

UNION is what you are looking for

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜