M
M
McMike2019-07-04 10:21:55
PostgreSQL
McMike, 2019-07-04 10:21:55

How to use a field alias in a query condition?

I have a query like
select id, email, (firstname || ' ' || lastname) as fullname
from user
How to use fullname alias in Where condition?
select id, email, (firstname || ' ' || lastname) as fullname
from user
where fullname like 'abc'
Swears there is no fullname field

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Melkij, 2019-07-04
@melkij

No way. In the where section, the fields from the select do not yet exist.
Duplicate the condition, wrap it in another select, make a stored function and call it in where and in select.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question