Paste this into a new question or an answer at dba.stackexchange.com:
<!-- --> > create table leads (lead_id int, status int, owner int); > insert into leads values (3653, 18, 6585993); > insert into leads values (3984, 3, 6585993); > insert into leads values (4100, 18, 6585993); > insert into leads values (8916, 21, 6585993); > insert into leads values (20329, 1, 6585993); > > <pre> > ✓ > > ✓ > > ✓ > > ✓ > > ✓ > > ✓ > </pre> <!-- --> > SELECT > lead_id, status, owner > FROM > leads > WHERE > owner = 6585993 > AND ((`status` = 1) OR (`status` = 21) OR (`status` = 3)) > ORDER BY > CASE `status` > WHEN 1 THEN 0 > WHEN 21 THEN 1 > WHEN 3 THEN 2 > END > LIMIT 1 > ; > > <pre> > lead_id | status | owner > ------: | -----: | ------: > 20329 | 1 | 6585993 > </pre> *db<>fiddle [here](https://dbfiddle.uk/?rdbms=mysql_5.7&fiddle=b1ed303a7311ad0e4bb4e9aa2c842a23)*
back to fiddle