Skip to content
Advertisement

Using ORDER BY and FIELD function to get single value to each custom list

I have a table named orders having 2 columns orderNumber & status as follow :

JavaScript

I want to get single status with order number order by custom list like this:

JavaScript

I have try this query for that:

JavaScript

But this give me all sorted result.

Advertisement

Answer

It looks like you want to group by status, selecting the minimum orderNumber for each status value, and then sort according to your FIELD expression. You can do that with this query:

JavaScript

Output:

JavaScript

Demo on db-fiddle

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement