i have the following SQL:
SELECT A.*,
(SELECT answer FROM [tblAnswers] B
WHERE B.memberID = A.memberID AND QuestionID = 3) AS ethnicity
FROM [tblMembers] A
WHERE
LOWER(gender) = 'm'
AND ethnicity = 'Sephardi'
and i get the error Invalid column name 'ethnicity'
referring to the last reference to that column.
Question: How come this column is not available to the WHERE
clause?
I know that if i do the following, it works:
SELECT A.*,
(SELECT answer FROM [tblAnswers] B WHERE B.memberID = A.memberID AND QuestionID = 3) AS ethnicity
FROM [tblMembers] A
WHERE
LOWER(gender) = 'm'
AND convert(nvarchar, (SELECT answer FROM [tblAnswers] B WHERE B.memberID = A.memberID AND QuestionID = 3)) = 'Sephardi'