Как можете да GROUP BY id_thread
когато няма id_thread
колона във вашата таблица?
SELECT *
FROM contacts
WHERE id_receiver = 1
--- GROUP BY id_thread
--- removed
ORDER BY created DESC
LIMIT 1 --- only show one row
Въз основа на вашите коментари това, което искате, е най-новото (подредено по created
) ред за всяка id_thread
, което е различна и по-сложна заявка. Има дори маркер за този вид заявки, наречен [greatest-n-per-group]
.
SELECT c.*
FROM contacts AS c
JOIN
( SELECT id_thread, MAX(created) AS created
FROM contacts
WHERE id_receiver = 1
GROUP BY id_thread
) AS g
ON (g.id_thread, g.created) = (c.id_thread, c.created)
WHERE c.id_receiver = 1