Answer the question
In order to leave comments, you need to log in
How to make a search query for unique values from the end by condition?
You need to make groupBy by uniqueid, and display only those groups where the last entry in the group has status='no';
That is, one row with id = 3 should be displayed from this table
Answer the question
In order to leave comments, you need to log in
select max(t1.id), t1.uniqueid, t1.status
from table1 t1
left join table1 t2 on t2.uniqueid = t1.uniqueid
and t2.status <> 'no'
where t2.id is null
group by t1.uniqueid
As an option:
SELECT SUBSTRING_INDEX(GROUP_CONCAT(id ORDER BY id DESC), ",", 1) as id FROM mytable WHERE status="no" GROUP BY uniqueid
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question