ควิซ SQL: Join Pitfalls

This SQL quiz collects the join mistakes that produce wrong numbers without any error. You will see a LEFT JOIN turned into an inner join by WHERE, totals multiplied by fan-out, NULL keys that never match and other traps that show up in real reports and interviews.

ยาก 10 ข้อ ~8 นาที ผ่านที่ 80% SQLite

เลือกโหมด

กำลังเล่นแบบผู้เยี่ยมชม: เข้าสู่ระบบเพื่อเก็บ XP และ streak

ตัวอย่างคำถาม

ข้อ 1 จาก 10

The goal is every customer, with their big orders if any. What does this print?

CREATE TABLE customers (id INTEGER, name TEXT);
CREATE TABLE orders (id INTEGER, customer_id INTEGER, amount INTEGER);
INSERT INTO customers VALUES (1, 'Ann'), (2, 'Bob'), (3, 'Cy');
INSERT INTO orders VALUES (10, 1, 10), (11, 1, 50), (12, 3, 5);
SELECT c.name
FROM customers c
LEFT JOIN orders o ON o.customer_id = c.id
WHERE o.amount > 20
ORDER BY c.name;
ดูเฉลย

A. Ann WHERE runs after the join, and for Bob o.amount is NULL, so NULL > 20 is not true and his row is dropped (Cy's 5 fails too). A condition on the right table in WHERE turns the left join into an inner join.

ควิซนี้มีเนื้อหาอะไรบ้าง

  • Filtering a LEFT JOIN in WHERE vs in ON
  • Fan-out when joining two one-to-many tables
  • Why NULL keys never match
  • A later INNER JOIN undoing a LEFT JOIN
  • SUM(DISTINCT) and duplicate rows

คำถามที่พบบ่อย

ต้องมีบัญชีไหม?

ไม่ต้อง ใครก็เล่นได้ เข้าสู่ระบบเพื่อเก็บ XP, streak, เหรียญตรา และประวัติ

ทำซ้ำได้ไหม?

ได้ ระบบเก็บคะแนนที่ดีที่สุดไว้ และสลับคำถามกับตัวเลือกใหม่ทุกครั้ง