http://sqlfiddle.com/#!2/37dd94/17
如果我做SELECT DISTINCT
我得到的结果和做SELECT
一样。
在查询结果中,您将看到两个包含区域“Evora”的活动。
只能出现一个。
有线索吗?
最佳答案
下面的查询(SQL FIDDLE)如何:
SELECT GROUP_CONCAT(APA_T.district), t.name
FROM tbl_activity AS t
JOIN tbl_activity_package AS ap ON t.id = ap.id_activity
JOIN
(
SELECT DISTINCT apa.district AS district,
(
SELECT s1.id_activity_package
FROM tbl_activity_package_address s1
WHERE apa.district = s1.district
ORDER BY s1.id DESC
LIMIT 1
) AS idActivityPackage
FROM
tbl_activity_package_address apa
ORDER BY apa.district
) AS APA_T
ON ap.id = APA_T.idActivityPackage
GROUP BY t.name
ORDER BY APA_T.district;
上面的查询将消除额外的
Faro
和Evora
。关于mysql - 我们可以对group_concat(distinct somefield)做一个DISTINCT吗?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/23544348/