select tb0.id as id, tb1.name as n1,tb2.name as n2,tb3.name as n3 from tb_name0 tb0, tb_name1 tb1, tb_name2 tb2, tb_name3 tb3 where tb0.n1=tb1.n1 and tb0.n2=tb2.n2 and tb0.n3=tb3.n3
SELECT 表0.id AS id,表1.n1 AS n1,表2.n2 AS n2,表3.n3 AS n3 FROM ((表0 INNER JOIN 表1 ON 表0.n1=表1.n1) INNER JOIN 表2 ON 表0.n2=表2.n2) INNER JOIN 表3 ON 表0.n3=表3.n3
[Quote=引用 8 楼 jhone99 的回复:]
select a.id
, (select name from 表1 where n1=a.n1) as n1
, (select name from 表2 where n2=a.n2) as n2
, (select name from 表3 where n3=a.n3) as n3
from 表0 a
[/Quote]
[Quote=引用 2 楼 alifriend 的回复:]
select a.id,b.name as n1,c.name as n2,d.name as n3 from 表0 a join 表1 b on a.n1=b.n1 join 表2 c on a.n2=c.n2 join 表3 d on a.n3=c.n3
[/Quote]
支持2楼架写法。但是数据量大时,就建议使用存储过程.
select a.id
, (select name from 表1 where n1=a.n1) as n1
, (select name from 表2 where n2=a.n2) as n2
, (select name from 表3 where n3=a.n3) as n3
from 表0 a