oracle sql无效标识符错误

时间:2016-12-04 01:27:27

标签: sql oracle sqlplus ddl dml

我试图在oracle数据库中运行以下语句:

select nfl_player.first_name, nfl_player.last_name
from nfl_player
where player_id IN 
    (select nfl_player.player_id as pid
        from nfl_player
        where pid=nfl_team_roster.player_id
        and nfl_team_roster.team_id= 4
    );

出于某种原因,当我运行它时,我收到以下消息:

and nfl_team_roster.team_id= 4
    *
ERROR at line 7:
ORA-00904: "NFL_TEAM_ROSTER"."TEAM_ID": invalid identifier

我已经仔细检查过,我的语法正确(或至少我相信)。该列存在。我在下面列出了该表的架构。什么会给我这个错误?

CREATE TABLE NBA_Team_Roster(
roster_ID number primary key,
team_id number,
player_id number unique,
foreign key (team_id) references NBA_Team(team_id),
foreign key (player_id) references NBA_Player(player_id)
);

非常感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

您编写的子查询中存在错误,您在子查询中错误放置了表名,并在连接条件中使用了别名。

 select np.first_name, np.last_name
from nfl_player np
where np.player_id IN 
    (select r.player_id as pid
        from NBA_Team_Roster r
        where r.team_id= 4);