Skip to content
Advertisement

How to query with a preference with LIKE?

I have this query, using Postgres:

which returns this result :

But how to have ‘GES.PAY’ the first line of the result , like that :

In other words I would like the exact name in first line, then the other cases. Is it possible to do that in one simple query, without using Levenshtein functions?

Advertisement

Answer

You can do conditional ordering:

In Postgres you can also express this as:

Th latter works because (condition)::int returns 1 if the condition is fulfilled, else 0.

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