Ok I have a table with an indexed key and an indexed field. I need to find all records with a specific value and return a string. I would like to know if I can order multiple values.
Example:
id x_field
pseudo: would like the results to be ordered as follows: where ORDER BY x_field = 'f', 'p', 'i', 'a'
SELECT * FROM table WHERE id NOT IN (126) ORDER BY x_field 'f', 'p', 'i', 'a'
Thus, the results will be as follows:
id x_field
The syntax is valid, but when I execute the query, it never returns any results, even if I limit it to 1 record. Is there another way to do this?
Think of x_field as test results, and I need to check all the records that fall into state. I would like to order test results using unsuccessful values, passed values. Therefore, I could check the failed values ββfirst, and then the passed values ββwith ORDER BY.
What I can not do:
- GROUP BY, since I need to return certain record values
- WHERE x_field IN ('f', 'p', 'i', 'a'), I need all the values, since I'm trying to use one query for several validation tests. And x_field values ββare not in DESC / ASC order
After writing this question, I start to think that I need to rethink this, lol!
sql sql-order-by postgresql
Phill Pafford Jun 13 2018-11-11T00: 00Z
source share