且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

MySQL查询多对多关系

更新时间:2023-02-15 18:26:09

此查询结构避免了使用唯一子句的情况(前提是解析表中没有重复的记录).

This query structure avoids the need for a distinct clause (provided there are no duplicate records in the resolution table).

SELECT p.PlantID
FROM
  Plant p INNER JOIN PlantAttribute pa
    ON p.PlantID = pa.PlantID AND pa.AttributeID = 1
  INNER JOIN PlantAttribute pa2
    ON p.PlantID = pa2.PlantID AND pa2.AttributeID = 2;