SQL Joins · Question 18 · Hard

SQL Joins question 18

Table Invoices:
inv_id | customer | total
1 | Zoya | 1000
2 | Arun | 500

Table InvoiceItems:
inv_id | item
1 | Pen
1 | Book
1 | Bag
2 | Lamp

total is stored once per invoice. What does this query return?

SELECT SUM(i.total)
FROM Invoices i
JOIN InvoiceItems it ON i.inv_id = it.inv_id;
  1. 1500
  2. 3000
  3. 3500
  4. 4000
Answer and explanation

Answer: C. 3500

Explanation: The join repeats an invoice row once for every item it has. Invoice 1 appears 3 times and invoice 2 once, so the sum is 3 × 1000 + 500 = 3500, not the true total of 1500.

Previous: Table Riders: rider_id | name 1 | Manoj 2 | Nisha 3 | Om Table Trips: trip_id… · Next: Table Staff: emp_id | name | manager_id 1 | Nandini | NULL 2 | Omkar | 1 3 |…

Practise sql joins

Try a fresh set of sql joins questions with an explanation after every answer, free and without signing up: SQL Joins practice. Or sit a full placement mock test.

More sql joins questions

More sql practice

Aggregates & GROUP BY · Subqueries & CTEs · Window Functions · NULL Handling · SQL Functions & CASE · UNION, INTERSECT & EXCEPT · Tables, Keys & Constraints · DML & Transactions

LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge