讨教在存储过程里从四张表里查询数据

MySql 码拜 7年前 (2017-05-01) 1194次浏览
目前本人有四张表,表结构一摸一样(具体历史原因不在深究了讨教在存储过程里从四张表里查询数据)。table1,table2,table3,table4
现在只想查出最四张表里的最后一条记录。
select * from table1 where DATE_SUB(CURDATE(),INTERVAL 2 DAY) <= date(yuer_time) order by id desc limit 0,1;
select * from table2 where DATE_SUB(CURDATE(),INTERVAL 2 DAY) <= date(yuer_time) order by id desc limit 0,1;
select * from table3 where DATE_SUB(CURDATE(),INTERVAL 2 DAY) <= date(yuer_time) order by id desc limit 0,1;
select * from table4 where DATE_SUB(CURDATE(),INTERVAL 2 DAY) <= date(yuer_time) order by id desc limit 0,1;
怎样写个存储过程,把这四张表查询出来的结果显示在一张表里。
万望各位高手不吝赐教!讨教在存储过程里从四张表里查询数据
解决方案

40

select * from table1 where DATE_SUB(CURDATE(),INTERVAL 2 DAY) <= date(yuer_time) order by id desc limit 0,1
union all
select * from table2 where DATE_SUB(CURDATE(),INTERVAL 2 DAY) <= date(yuer_time) order by id desc limit 0,1
union all
select * from table3 where DATE_SUB(CURDATE(),INTERVAL 2 DAY) <= date(yuer_time) order by id desc limit 0,1
union all
select * from table4 where DATE_SUB(CURDATE(),INTERVAL 2 DAY) <= date(yuer_time) order by id desc limit 0,1;

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明讨教在存储过程里从四张表里查询数据
喜欢 (0)
[1034331897@qq.com]
分享 (0)