0

我需要在以下查询中进行 Distinct 搜索:

$listings = $this->Listing->query("SELECT DISTINCT(Listing.listnumber),Listing.*, ClientEvent.*, Client.*, UserLog.*, Agent.* FROM listings Listing
                        LEFT JOIN client_events ClientEvent ON ClientEvent.listnumber = Listing.listnumber
                        LEFT JOIN clients Client ON Client.clnt_id = ClientEvent.clnt_id
                        LEFT JOIN user_logs UserLog ON UserLog.ul_item_id = Listing.listnumber
                        LEFT JOIN agents Agent ON Agent.agnt_id = Listing.agnt_id
                        WHERE Listing.off_id = '{$off_id}' AND (UserLog.ul_type = 'listing.new_listing' OR Listing.listnumber LIKE '3330%')");

但是,这给了我正确的结果,但重复。我需要不同的结果。

有任何想法吗?

4

1 回答 1

-1
    $listings = $this->Listing->query("SELECT Listing.listnumber FROM listings Listing
                            LEFT JOIN client_events ClientEvent ON ClientEvent.listnumber = Listing.listnumber
                            LEFT JOIN clients Client ON Client.clnt_id = ClientEvent.clnt_id
                            LEFT JOIN user_logs UserLog ON UserLog.ul_item_id = Listing.listnumber
                            LEFT JOIN agents Agent ON Agent.agnt_id = Listing.agnt_id
                            WHERE Listing.off_id = '{$off_id}' AND (UserLog.ul_type = 'listing.new_listing' OR Listing.listnumber LIKE '3330%') group by Listing.listnumber");
----------------------
Put your extar column not a tablename.*...

    $listings = $this->Listing->query("SELECT Listing.listnumber, colname1,.. FROM listings Listing
                            LEFT JOIN client_events ClientEvent ON ClientEvent.listnumber = Listing.listnumber
                            LEFT JOIN clients Client ON Client.clnt_id = ClientEvent.clnt_id
                            LEFT JOIN user_logs UserLog ON UserLog.ul_item_id = Listing.listnumber
                            LEFT JOIN agents Agent ON Agent.agnt_id = Listing.agnt_id
                            WHERE Listing.off_id = '{$off_id}' AND (UserLog.ul_type = 'listing.new_listing' OR Listing.listnumber LIKE '3330%') group by Listing.listnumber");
于 2012-10-11T09:57:56.987 回答