Link to home
Start Free TrialLog in
Avatar of drew22
drew22

asked on

WHERE ...IN () using concat()

Trying to find out what records from legacy.f_group  exist in survey.participant.

This works:

SELECT  con_id, lastname
FROM legacy.f_group
WHERE lastname
IN (

   SELECT lastname
    FROM survey.participant
)

...but when I try to narrow it down using 2 cols, I get an error:


SELECT  con_id, concat (lastname,zip) AS namezip
FROM legacy.f_group
WHERE namezip
IN (

    SELECT  concat (lastname,zip) AS namezip
    FROM survey.participant
)

#1054 - Unknown column 'namezip' in 'scalar IN/ALL/ANY subquery'


drew
Avatar of kupra1
kupra1

This is happening because Standard SQL doesn't allow you to refer to a column alias in a WHERE clause. This is because when the WHERE code is executed, the column value may not yet be determined.
You can use an alias to refer to a column in GROUP BY, ORDER BY, or HAVING clauses.
ASKER CERTIFIED SOLUTION
Avatar of kupra1
kupra1

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial