Я не знаю, почему этот SQL не возвращает строк:
SELECT team_rel.team_id
, team_rel.login_id
FROM team_rel
INNER JOIN team ON team_rel.login_id = team.login_id
WHERE team.login_id = '39'
AND NOT EXISTS (
SELECT 0
FROM team_rel
INNER JOIN team ON team_rel.login_id = team.login_id
AND team_rel.login_id = '39'
AND team_rel.team_id = team.id
)
в то время как следующий SQL (тот же, но без условия NOT EXISTS):
SELECT team_rel.team_id
, team_rel.login_id
FROM team_rel
INNER JOIN team ON team_rel.login_id = team.login_id
WHERE team.login_id = '39'
возвращается:
+---------+----------+
| team_id | login_id |
+---------+----------+
| 23 | 39 |
+---------+----------+
| 23 | 39 |
+---------+----------+
| 13 | 39 |
+---------+----------+
| 13 | 39 |
+---------+----------+
| 16 | 39 |
+---------+----------+
| 16 | 39 |
+---------+----------+
| 25 | 39 |
+---------+----------+
| 25 | 39 |
+---------+----------+
и подзапрос NOT EXISTS (тот же SQL с test для team_id) возвращает:
SELECT team_rel.team_id
, team_rel.login_id
FROM team_rel
INNER JOIN team ON team_rel.login_id = team.login_id
AND team_rel.login_id = '39'
AND team_rel.team_id = team.id
возвращается:
+---------+----------+
| team_id | login_id |
+---------+----------+
| 23 | 39 |
+---------+----------+
| 25 | 39 |
+---------+----------+
Я бы хотел, чтобы мой первый выбор вернул:
+---------+----------+
| team_id | login_id |
+---------+----------+
| 13 | 39 |
+---------+----------+
| 16 | 39 |
+---------+----------+
но он не возвращает никаких строк?!