-
慕哥9229398
SELECT `name`,`car` FROM table_a aINNER JOIN table_ab ab ON a.id = ab.id_aINNER JOIN table_b b ON ab.id_b = b.idPS:您也可以在没有任何连接的情况下执行此操作,在某些情况下,它更快更干净。SELECT `name`,`car` FROM table_a a,table_b b, table_ab abWHERE a.id = ab.id_a AND ab.id_b = b.id在本例中,DESCRIBE 显示了相同的结果,因此任一选项都适用。
-
慕森王
我想你想要joins 和聚合:select a.name, group_concat(car) as carsfrom ab join a on a.id = ab.id_a join b on b.id = ab.id_bgroup by a.id, a.name;
-
aluckdog
你需要两个加入 select a.name, b.car from table_ab ab inner join table_a a ON a.id = ab.id_a inner join table_b b ON b.id = ab.id_b
-
LEATH
您必须加入表,按名称分组并group_concat()结合使用concat():select concat(a.name, ' has ', group_concat(car separator ' and ')) colfrom table_a a inner join table_ab ab on ab.id_a = a.idinner join table_b b on ab.id_b = b.idgroup by a.id, a.name请参阅。结果:| col || --------------------- || tom has car1 and car2 || max has car1 |