目前尚未从MYSQL数据库分配的返回值

时间:2014-09-12 08:36:45

标签: mysql sql

我有一块mysqly,目前正在返回当前正在使用的所有团队ID。但是,在这种情况下,我希望它返回尚未分配的所有团队ID。

如何实现这一目标?

SELECT

*                                          

FROM 
 leagueInformation li                                            

 INNER JOIN 
    teams t ON t.teamID = li.teamID

 WHERE li.leagueID = 1 AND li.seasonID = 1 

GROUP BY 
  t.teamName

ORDER BY 
  t.teamID

2 个答案:

答案 0 :(得分:0)

试试这个:

SELECT * 
FROM teams 
WHERE TeamID NOT IN (
    SELECT TeamID 
    FROM leagueInformation 
    WHERE leagueID = 1 AND seasonID = 1
)

答案 1 :(得分:0)

左/右连接选项:

SELECT t.*                                          
FROM 
 leagueInformation li RIGHT JOIN 
 teams t ON t.teamID = li.teamID
WHERE li.teamID IS NULL

或EXISTS:

SELECT t.*                                          
FROM 
 teams t
WHERE NOT EXISTS (SELECT * FROM leagueInformation WHERE teamID = t.teamID)