Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.
Shade in the A or B circle for each question.
Draw a line connecting each item on the left to its match on the right.
| Left column | Right column | |
|---|---|---|
| 1cur.execute(join_sql) | AA single-quoted string with double quotes cannot span several lines, so Python raises a syntax error. Use triple quotes for a multi-line SQL string. | |
| 2for first, subject, mark in rows: | BRuns a JOIN query held in one string variable and gets the joined rows ready to fetch | |
| 3A long JOIN query can be stored as one readable string by using a multi-line string | Crows = cur.fetchall() | |
| 4Fetching all rows of a join gives a list of tuples, each holding one student field and one subject field | DUnpacks each joined row tuple into variables, with fields that came from different tables | |
| 5join_sql = "SELECT students.firstName, results.mark FROM students JOIN results ON students.studentId = results.studentId" | Ejoin_sql = """SELECT students.firstName, results.mark FROM students JOIN results ON students.studentId = results.studentId""" | |
| 6for first, subject in rows: # rows have 3 fields | FThe loop unpacks two variables, but each joined row tuple holds three fields, so Python raises a ValueError. Unpack one variable per selected field. |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
cur.execute(join_sql) — Runs a JOIN query stored in one string. Each row fetched back is a tuple holding fields from both tables, which you can unpack into variables.cur.execute(sql)
rows = cur.fetchall()sql = """SELECT firstName, mark
FROM students JOIN results
ON students.studentId = results.studentId"""cur.execute(sql)
for row in cur.fetchall():
print(row)row = cur.fetchone()
name, mark = row
print(name, "got", mark)sql = """SELECT name, quantity
FROM products JOIN orders
ON products.productId = orders.productId"""