具有LEFT JOIN的表标识符

时间:2011-11-15 02:35:24

标签: mysql left-join

如何加入 tableD.id = tableC.id AND tableD.id = tableE.id ? tableD和E都可能有0行,我需要计算它们,即。 SELECT COUNT(E.id)。问题是我不知道在哪里声明表标识符。

我试过了:

FROM tableB B,tableD D,tableE E ...

LEFT JOIN(tableC C,tableD D)ON ...

SELECT B.*, COUNT(C.id) AS cCount 
FROM tableB B
LEFT JOIN (tableC C)
ON (B.id = C.id)
GROUP BY B.id

1 个答案:

答案 0 :(得分:1)

从你的问题中判断出你在寻找什么是有点困难,但我相信这就是它:

SELECT B.*, COUNT(C.id) AS cCount 
FROM tableB AS B
LEFT JOIN tableC AS C ON B.id = C.id
LEFT JOIN tableD AS D ON C.Id = D.Id
LEFT JOIN tableE AS E ON D.Id = E.Id
GROUP BY B.id