mysql一个表中多个字段对应另一个表的id如何查询?

2024-10-28 15:52:25
有2个网友回答
网友(1):

SELECT m.aid,m.b1id,n.bcon,m.b2id as b2id,o.bcon as b2con, m.b3id as b3id,p.bcon as b3con FROM `test` as m INNER JOIN test1 as n on m.b1id=n.bid INNER JOIN test1 as o on m.b2id=o.bid INNER JOIN test1 as p on m.b3id=p.bid;

结果:

网友(2):

select n.aid, m.bid ,m.bcon , l.bid,l.bcon,o.bid ,o.bcon from
a n join b m on n.b1id=m.bid
join b l on n.b2id=l.bid
join b o on n.b3id=o.bid