Consider the following tables in a database called SPORTS. GAMES GID | GNAME |…
2023
Consider the following tables in a database called SPORTS.
GAMES
GID | GNAME | FEES
G01 | Football | 300
G02 | Cricket | 1000
G03 | Basketball | 500
PLAYERS
PID | PNAME | SEX | GID
P101 | Amrita | F | G03
P103 | Ameena | F | G02
P107 | Angel | F | G02
P109 | Aman | M | G03
Which is the best command to display the player name (PNAME) and the respective game name (GNAME)?
- A.
SELECT PNAME, GID FROM PLAYERS;
- B.
SELECT PNAME, GNAME FROM GAMES, PLAYERS WHERE GAMES.GID=PLAYERS.GID;
- C.
SELECT PNAME, GNAME FROM GAMES, PLAYERS;
- D.
SELECT PNAME, GNAME FROM GAMES, PLAYERS WHERE PLAYERS.PID=GAMES.GID;
Attempted by 1472 students.
Show answer & explanation
Correct answer: B
PNAME is stored in PLAYERS and GNAME is stored in GAMES. To display each player's respective game, join the two tables on their common column GID.
Correct command:
SELECT PNAME, GNAME FROM GAMES, PLAYERS WHERE GAMES.GID = PLAYERS.GID;
This gives: Amrita - Basketball, Ameena - Cricket, Angel - Cricket, Aman - Basketball.