Skip to content
Advertisement

Conditional Query Using “AS” field

Above you can see my code. It is currently returning exactly the output I want when you remove the “WHERE” function. I’m adding the “WHERE” function and attempting to access the new column I made called “NPO”. It seems as if the column does not exist to the SQL editor, but it does exist when the query is ran. How do I access it?

Thanks!

Advertisement

Answer

Enclose your query into a “table expression” so you can produce a named column. Then you can use it in the WHERE clause:

Note: “table expressions” are also called “derived tables” and “inline views” by different teams of people.

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