Answer the question
In order to leave comments, you need to log in
How to set a condition on a renamed column in SQL?
Good day to all! :)
Can you please tell me how to set a condition for a renamed column in SQL?
Here's an example of how I'm trying to do it:
SELECT user_id, concat(user_name, " ", user_surname, " ", user_patronim) AS fio
FROM users
WHERE fio like 'Абв%'
#1054 - Unknown column 'fio' in 'where clause'
Answer the question
In order to leave comments, you need to log in
in this case, fio is an alias, MySQL cannot do WHERE by aliases, so fam needs to
either rewrite the WHERE construct to
WHERE concat(user_name, " ", user_surname, " ", user_patronim) like 'Abc%'
or use the HAVING construct instead of WHERE, ex:
HAVING fio like 'Abc%'
Let him use WHERE concat(user_name, " ", user_surname, " ", user_patronim) like 'Abc%'
Then there will be no problems with aggregation of extra data when he decides to add GROUP BY
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question