简体   繁体   中英

oracle sql invalid identifier error

I am trying to run the following statement in the oracle database:

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
    );

For some reason when I run it, I get the following message:

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

I have double checked and I have my syntax right (or at least I believe so). The column exists. I have included my schema for that table below. What would be giving me this error?

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)
);

Any help would be greatly appreciated.

nfl_team_roster table is not used in your query. I think you misplaced the table name in sub-query

SELECT first_name, 
       last_name 
FROM   nfl_player nf 
WHERE  player_id IN (SELECT ntr.player_id AS pid 
                     FROM   NBA_Team_Roster ntr --Here 
                     WHERE  nf.pid = ntr.player_id 
                            AND ntr.team_id = 4); 

Use Alias name instead of full table name to refer columns it makes the query more readable.

there is a error in sub query you written, you misplaced the table name in sub-query and used alias name in join condition.

 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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM