在MySql查询中,我正在通过单个访问多个表,如下所示的情况查询。
select Type,count(*) as Count
from Equipment as eq,Manager as m,Holder as e
where m.PARENTID=e.ID
AND e.holderType='rich'
AND eq.ID=m.ID
group by Type;
我正在获得输出,但我不知道这是正确的方法。这是否是正确的方法?
答案 0 :(得分:0)
是的,您可以使用单个where子句来访问多个表
答案 1 :(得分:0)
JOIN是访问多个表的首选方式。使用符合您要求的JOIN类型,并使用应该连接表的ON子句。
示例
SELECT Type,count(*) as Count
FROM Equipment as eq
LEFT JOIN Manager as m ON eq.ID=m.ID
LEFT JOIN Holder as e ON m.PARENTID=e.ID
AND e.holderType='rich'
GROUP BY Type;