Skip to content
Advertisement

How to use an ALIAS in a PostgreSQL ORDER BY clause?

I have the following query:

Running it in PostgreSQL 8.1.23 i get this error:

Query failed: ERROR: column “global_stock” does not exist

Anybody can help me to put it to work? I need the availale items first, after them the unnavailable items. Many thanks!

Advertisement

Answer

You can always ORDER BY this way:

or wrap it in another SELECT:

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