¿Cómo puedes GROUP BY id_thread
cuando no hay id_thread
columna en su tabla?
SELECT *
FROM contacts
WHERE id_receiver = 1
--- GROUP BY id_thread
--- removed
ORDER BY created DESC
LIMIT 1 --- only show one row
Según sus comentarios, lo que desea es lo último (ordenado por created
) fila para cada id_thread
, que es una consulta diferente y más compleja. Incluso hay una etiqueta para este tipo de consultas, denominada [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