目前本人有四张表,表结构一摸一样(具体历史原因不在深究了 )。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;
怎样写个存储过程,把这四张表查询出来的结果显示在一张表里。
万望各位高手不吝赐教!
现在只想查出最四张表里的最后一条记录。
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;
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;