...
WHERE
x_field IN ('f', 'p', 'i', 'a') ...
ORDER BY
CASE x_field
WHEN 'f' THEN 1
WHEN 'p' THEN 2
WHEN 'i' THEN 3
WHEN 'a' THEN 4
ELSE 5 --needed only is no IN clause above. eg when = 'b'
END, id
More Related Contents:
- Sort by column ASC, but NULL values first?
- PostgreSQL DISTINCT ON with different ORDER BY
- ORDER BY the IN value list
- Optimize query with OFFSET on large table
- Sorting null values after all others, except special
- Sort NULL values to the end of a table
- PostgreSQL ORDER BY issue – natural sort
- Why do NULL values come first when ordering DESC in a PostgreSQL query?
- Alphanumeric sorting with PostgreSQL
- How to concatenate strings of a string field in a PostgreSQL ‘group by’ query?
- How to use RETURNING with ON CONFLICT in PostgreSQL?
- Does PostgreSQL support “accent insensitive” collations?
- PostgreSQL: running count of rows for a query ‘by minute’
- Split comma separated column data into additional columns
- How to delete duplicate entries?
- Transpose latest rows per user to columns
- How to include “zero” / “0” results in COUNT aggregate?
- SQL SELECT speed int vs varchar
- delete “column does not exist”
- How to use Oracle ORDER BY and ROWNUM correctly?
- How to create a temporary function in PostgreSQL?
- Postgres Case Sensitivity
- Polymorphism in SQL database tables?
- How to round an average to 2 decimal places in PostgreSQL?
- Explain JOIN vs. LEFT JOIN and WHERE condition performance suggestion in more detail
- postgresql: INSERT INTO … (SELECT * …)
- Return multiple columns and rows from a function PostgreSQL instead of record
- Postgres error updating column data
- SQL LIKE condition to check for integer?
- How to detect query which holds the lock in Postgres?