方案:通过union连接查询出所有需要的特殊标签,然后在通过left join与union中的结果集做多表比较。
sql
select t.`code`,a.`count` as count_a,b.`count` as count_b from( select `code` from tmp_a a union select `code`from tmp_b b) t left join tmp_a a on t.`code`=a.`code` left join tmp_b b on t.`code`=b.`code`;
两张表
select * from tmp_a; select * from tmp_b;