想象一下,我们有2个表,我想返回table1的所有列和table2的一个列,而不是在哪里过滤table2的列
看一下这个查询:
SELECT table1.* , table2.name AS anotherName
FROM table1 INNER JOIN table2 ON table1.id = table2.id
WHERE anotherName LIKE '%something here %'
我知道我不能像这样使用anotherName,但出现错误,但我不知道要解决此问题
在having
子句中检测到别名,但在where
子句中未检测到别名。如果你坚持在条件使用别名,您需要使用having
,如果不是where
:
HAVING anotherName LIKE '%something here %'
否则,您必须调用原始名称:
WHERE t2.name LIKE '%something here %'
您也可以检查此链接以查看为什么不能在where
子句中使用别名。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句