我需要在以下查询中进行不同的搜索:
$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%')");
然而,这给了我正确的结果,但重复。我需要DISTINCT结果。
有什么想法吗?
答案 0 :(得分:-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");