A
A
alehandroWEB2018-10-16 13:28:18
MySQL
alehandroWEB, 2018-10-16 13:28:18

How to make a search query for unique values ​​from the end by condition?

5bc5b98e57b64300069797.png
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

2 answer(s)
D
Dmitry Telepnev, 2018-10-16
@alehandroWEB

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

S
Sergey Predvoditelev, 2018-10-16
@NikoX

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 question

Ask a Question

731 491 924 answers to any question