右表我有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)将帮助你 –