SELECT
ID
, NAME
, EMAIL
, (SELECT Address FROM TABLE1 where T1ID=ID) as NewAddress
FROM TABLE2
WHERE NewAddress LIKE '%string%';
在此查询中,我想检查NewAddress Column上的条件, 我不想传递子查询中的条件(有一些原因)......
我的意思是说我想在这里检查子查询的别名名称NewAddress
这里我收到'where子句'
中的未知列'NewAddress'的错误答案 0 :(得分:1)
我的建议是取消子查询并使用连接重写您的查询:
SELECT t2.ID,
t2.Name,
t2.Email,
t1.Address AS NewAddress
FROM Table2 AS t2
INNER JOIN Table1 AS t1
ON t1.ID = t2.T1ID
WHERE t1.Address like '%string%';
它将解决您对该列进行过滤的问题,几乎肯定会表现得更好。一个双赢的场景。
答案 1 :(得分:0)
您可以将查询的一部分放在另一个子查询中,例如:
SELECT * FROM
(
SELECT
ID
, NAME
, EMAIL
, (SELECT Address FROM TABLE1 where T1ID=ID) as NewAddress
FROM TABLE2
) AS SUBQUERY_01
WHERE NewAddress LIKE '%string%';