select Name from table4 join
(select 'table1' as tableID,ID,name from table1
union
select 'table2' as tableID,ID,name from table2
union
select 'table3' as tableID,ID,name from table3) as a
on table4.tableID=a.tableID and table4.ID=a.ID
不知道行不行,试试
(select 'table1' as tableID,ID,name from table1
union
select 'table2' as tableID,ID,name from table2
union
select 'table3' as tableID,ID,name from table3) as a
on table4.tableID=a.tableID and table4.ID=a.ID
不知道行不行,试试
union
select t2.name from table4 t4 join table2 t2 on t4.ID=t2.ID and t4.tableID='table2'
union
select t3.name from table4 t4 join table3 t3 on t4.ID=t3.ID and t4.tableID='table3'