34,594
社区成员
发帖
与我相关
我的任务
分享
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;
declare @str varchar(10)
set @str=''
if exists (select 1 from B where id in(select top 10 id from A))
begin
set @str='tbl_A'
if exists (select 1 from C where id in(select top 10 id from A))
BEGIN
set @str=@str+'tbl_B'
if exists (select 1 from D where id in(select top 10 id from A))
begin
set @str=@str+'tbl_D'
end
END
print '匹配到的表为:'+@str
end
--try