我有一个这样的查询:
$sql_place = "SELECT * FROM place
INNER JOIN join_appointment_place
ON join_appointment_place.id_place = place.id_place
INNER JOIN join_event_appointment
ON join_appointment_place.id_appointment = join_event_appointment.id_appointment
WHERE join_event_appointment.id_event = " . $EVENT_ID . "
ORDER BY place.title, place.category";
问题是我需要返回所有不同的地方titles
。所以我应该使用DISTINCT
. 但是如何选择DISTINCT
title
并同时返回所有其他值?
$sql_place = "SELECT
DISTINCT
place.id_place,
place.avatar,
place.category,
place.title,
place.description,
place.address,
place.latitude,
place.longitude,
place.email,
place.web,
place.shared FROM place
INNER JOIN join_appointment_place
ON join_appointment_place.id_place = place.id_place
INNER JOIN join_event_appointment
ON join_appointment_place.id_appointment = join_event_appointment.id_appointment
WHERE join_event_appointment.id_event = " . $EVENT_ID . "
ORDER BY place.title, place.category";
以上是我试过的。但我担心将 DISTINCT 不仅应用于title
,而且应用于每个选定的列,这不是我想要的。谢谢你的帮助 :)