select a.*,if(b.aid is not null,'B',if(c.aid is not null,'C','D')) as tableNamefrom aleft join b on a.id=b.aidleft join c on a.id=c.aidleft join d on a.id=d.aidorder by a.id limit 10; [解决办法]
[解决办法]
SQL code
select a.id,u.tfrom A left join (select 'B' as t,id from Bunion allselect 'C' as t,id from Bunion allselect 'D' as t,id from B) u on a.id=u.id [解决办法]
[解决办法] 贴建表及插入记录的SQL,及要求结果出来看看
select a1.id,b1.bz from A a1 left join ( select 'B' as bm,id from b union all select 'C' as bm,id from c union all select 'D' as bm,id from d ) b1 on a1.id=b1.id order by a1.id desc limit 10
or
select a1.id,b1.bz from A a1 left join ( select 'B' as bm,id from b union all select 'C' as bm,id from c union all select 'D' as bm,id from d ) b1 on a1.id=b1.id where b1.id is not null order by a1.id desc limit 10 [解决办法] select a.id,u.t from A left join ( select 'B' as t,id from B union all select 'C' as t,id from B union all select 'D' as t,id from B ) u on a.id=u.id order by a1.id desc limit 10
[解决办法]
SQL code
select a.id, (select id from b) as bid, (select id from c) as cid, (select id from d) as didfrom Alimit 10 [解决办法]