CBSE · 083Class XII · 2022Section A2 marks
Question 04
7 June 2022 · Computer Science (083)
Consider the following SQL table MEMBER in a SQL Database CLUB :
Table : MEMBER
| M_ID | NAME | ACTIVITY |
|---|---|---|
| M1001 | Amina | GYM |
| M1002 | Pratik | GYM |
| M1003 | Simon | SWIMMING |
| M1004 | Rakesh | GYM |
| M1005 | Avneet | SWIMMING |
Assume that the required library for establishing the connection between Python and MySQL is already imported. Also assume that DB is the database connection object for the database CLUB.
Predict the output of the following code :
python
MYCUR = DB.cursor()
MYCUR.execute("USE CLUB")
MYCUR.execute("SELECT * FROM MEMBER WHERE ACTIVITY='GYM' ")
R = MYCUR.fetchone()
for i in range(2):
R = MYCUR.fetchone()
print(R[0], R[1], sep="#")Answer
text
M1002#Pratik
M1004#RakeshExplanation
The SELECT returns the 3 GYM members in order: Amina, Pratik, Rakesh. The first fetchone() consumes Amina (but doesn't print). The loop then fetches and prints the next two rows — Pratik and Rakesh — joining M_ID and NAME with '#'.