The following code is producing a list with the non-expired rows on top, then the ones with unknown expiry date and at the end the already expired (all of them in ascending order). The problem is that I want the last block of already expired rows to be in descending order so it displays the rows that expired more recently on top of that block without altering the order of the other top blocks.
Basically, I am trying to find a way to incorporate two “ORDER BY” clauses within the same recordset…
Any ideas? Thanks
SELECT *
FROM prueba
WHERE UPPER(CONCAT(Company,Deal,keywords,Type,Expiry,Name)) LIKE UPPER(%s)
ORDER BY (CASE
WHEN prueba.Expiry = 'UNKNOWN' THEN 1
WHEN prueba.Expiry < CURRENT_DATE THEN 2
END)
, prueba.Expiry ASC
Try this
DEMO FIDDLE