Answer the question
In order to leave comments, you need to log in
How to choose the last unique value?
There is a table with data
From it you need to pull out the last records with a unique value of the column "counter_id" I'm trying
to make such a query
SELECT * FROM (SELECT * FROM countersRecords ORDER BY id DESC) AS gagaga GROUP BY gagaga.counter_id
SELECT * FROM countersRecords GROUP BY counter_id ORDER BY id ORDER BY id DESC
Answer the question
In order to leave comments, you need to log in
SELECT r.id
FROM countersRecords r
WHERE r.id = (
SELECT MAX(id)
FROM countersRecords latest
WHERE latest.counter_id = r.counter_id
) t
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question