Hvordan kan du GROUP BY id_thread
når der ikke er nogen id_thread
kolonne i din tabel?
SELECT *
FROM contacts
WHERE id_receiver = 1
--- GROUP BY id_thread
--- removed
ORDER BY created DESC
LIMIT 1 --- only show one row
Baseret på dine kommentarer, er det, du ønsker, det seneste (ordnet efter created
). ) række for hver id_thread
, som er en anderledes og mere kompleks forespørgsel. Der er endda et tag til denne slags forespørgsler, kaldet [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