sql查询:
select
usr.username,
(
select usr2.username
from users as usr2
) as another_user
from users as usr
having usr.username != another_user
如何将usr.username
与子查询进行比较,例如命名为another_user
?
我想获得usr.username
不等于another_user
我尝试了WHERE
子句或HAVING
,但仍然出现错误
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax
答案 0 :(得分:0)
尝试
select
usr.username,
(
select username from users where ...
) as another_user
from users as usr
where usr.username <> another_user.username
答案 1 :(得分:0)
也许是这样的:
SELECT
*
FROM
(
select
usr.username,
(
....
) as another_user
from users as usr
) AS T
WHERE
NOT T.username = T.another_user