我需要一些帮助才能获得所需的结果,在本例中为 7(产品表中匹配的行数)。
相反,我得到的是 7 行,其计数基于 LEFT JOIN 中返回的行数。
SELECT count(p.id) as theCount 
            FROM products p 
            left join tablea a on p.id = a.productId 
            left join tableb b on p.id = b.productId 
            WHERE (a.col = 'val' or b.col = 'val')
group by p.id
如果我不按 p.id 分组,我会返回 28 行,这是 LEFT JOIN 中的所有行。
我知道这很简单,但我无法弄清楚。
谢谢。