右表我有2個表。如何從左表和匹配的記錄在mysql中的右表獲得全部記錄?我正在使用下面的查詢,但它只會從兩個表中獲得匹配的記錄。如何從左表總記錄和匹配的記錄形成的MySQL
SELECT post_id,COUNT(post_id) as pid,hostel_id,ht.user_id,hostel_name,
hostel_type,hostel_district,hostel_area,post_date,hostel_rent,hostel_respond,
h_contact_num,created_date,h_food_type
FROM hostels ht
left join histroy hr
ON ht.hostel_id =hr.post_id
WHERE ht.hostel_district=$city_code AND
ht.status='1' AND
hr.post_type='Hostel'
GROUP BY hr.post_id
ORDER by pid DESC
您可以顯示一些樣本數據來說明你想要的是什麼?在「GROUP BY」查詢的情況下,您對我的詢問不清楚。 –
你必須子句添加的所有列,除了'COUNT(POST_ID)爲pid'您的小組。 –
也許[這個問題](http://stackoverflow.com/questions/3453809/how-to-use-mysql-found-rows-in-php)將幫助你 –