注意,两张表的字段名最好保持相同
查询两张表的数据,包含相同的数据:
select id from tab_a where a='1'
union ALL
select id from tab_b where a='1'
order by time desc limit 0,10
查询两张表的数据,去掉相同的数据:
select id from tab_a where a='1'
union
select id from tab_b where a='1'
order by time desc limit 0,10
查询两张表合并后的总条数:
SELECT SUM(aa) from(
select COUNT(*) as aa
from tab_a where id='2'
union ALL
select COUNT(*) as aa
from tab_b
where id='2' )tab_c