假设我有4个相同的表:table1,table2,table3,table4
所有表都具有相同的结构: id总日期
我希望使用相同的条件从所有表中获取所有信息。我的意思是在1
中合并4个sql请求所以没有这4个sql,只有一个。请记住,所有表格的条件相同,在我们的案例中日期= 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'
感谢您的时间。
答案 0 :(得分:4)
(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')
你正在寻找