select a.*,if(b.aid is not null,'B',if(c.aid is not null,'C','D')) as tableName
from a
left join b on a.id=b.aid
left join c on a.id=c.aid
left join d on a.id=d.aid
order by a.id
limit 10;
------解决方案--------------------
------解决方案--------------------
SQL code
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
------解决方案--------------------
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 did
from A
limit 10
------解决方案--------------------