0
$select = "select  f.root_id,f.dateTime,f.name,count(fs.id) as sub_count,CONCAT(u.name,\" \",u.surname) as creator_name_surname".
            " from forum as f ".
            " left outer join users as u on u.id=f.creator_id".
            " left outer join forum as fs on fs.record_root_id=f.root_id"
            ;
    $params = " where fs.status=1 and f.status = 1 and f.record_root_id=$root_id and f.kullanici_firma_id=$kullanici_firma_id";

    $group_by =" GROUP BY f.root_id,f.dateTime,f.name";

This query does not list the rows in f with count(fs.id)=0. But I need to list all other rows no matter count 0 or greater. What is my problem?

4

1 に答える 1

2

WHERE フィルターの問題fs.status=1。これにより、テーブルの LEFT JOIN がforum fsINNER JOIN のように機能します。代わりに、そのフィルターを JOIN に配置する必要があります。

select  f.root_id,
    f.dateTime,
    f.name,
    count(fs.id) as sub_count,
    CONCAT(u.name,\" \",u.surname) as creator_name_surname
from forum as f 
left outer join users as u 
    on u.id=f.creator_id
left outer join forum as fs 
    on fs.record_root_id=f.root_id
    and fs.status=1 
where f.status = 1 
    and f.record_root_id=$root_id 
    and f.kullanici_firma_id=$kullanici_firma_id
GROUP BY f.root_id,f.dateTime,f.name
于 2013-05-28T21:03:55.087 に答える