1

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
4

2 に答える 2

0

試す

select
usr.username,
(
  select username from users where ...
) as another_user
from users as usr
where usr.username <> another_user.username
于 2012-06-08T13:32:20.673 に答える
0

多分このようなもの:

SELECT
    *
FROM
(
    select
    usr.username,
    (
      ....
    ) as another_user
    from users as usr
) AS T
WHERE
    NOT T.username = T.another_user
于 2012-06-08T13:32:42.477 に答える