fabrizio fabrizio - 1 year ago 84
MySQL Question

use fake column on where statement mysql

i have made a query of example for select some user and i created a fake column with the value 1 for use it on the where statement but it doesn't work. The error got is

unkown coulumn type_user



id | name | surname | type_user /* fake column */
1 Jhon Smith 1
2 Elis Sun 1

in select something like that:

SELECT id,name,surname, 1 as type_user WHERE type_user = 1

I know that with this logic is very stupid do this query but i want understand how i can use the fake column on where.

Answer Source

You can try doing it as a subquery:

    SELECT id,name,surname, 1 as type_user
    FROM table_name
) as `ta`
WHERE ta.type_user = 1;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download