空でない値を持つ行をグループ化する方法を知っていますか?
例えば:
ID title description address
------------------------------------
1 | john | row1 | EMPTY
1 | john | EMPTY | 2
1 | john | EMPTY | EMPTY
結果
ID title description address
------------------------------------
1 | john | row1 | 2
SELECT は UNION です:
SELECT
id,
title,
description,
address
FROM
(
SELECT a.id, a.title, b.value as description, "" as address
FROM #__content as a
LEFT JOIN #__fieldsattach_values as b ON a.id = b.articleid
WHERE a.catid IN (15, 16)
AND b.fieldsid = 4 AND a.language = "ca-ES" AND a.state = "1"
GROUP BY a.id UNION ALL SELECT a.id, a.title, "" as description , b.value as address
FROM #__content as a LEFT JOIN #__fieldsattach_values as b ON a.id = b.articleid
WHERE a.catid IN (15, 16) AND b.fieldsid = 5 AND a.language = "ca-ES"
AND a.state = "1" GROUP BY a.id
) AS z