ควิซ SQL: LEFT JOIN

This SQL quiz is about LEFT JOIN and the NULLs it brings with it. You will count matches without losing unmatched rows, find rows that have no partner and see how COUNT, SUM and table order behave with outer joins.

ปานกลาง 10 ข้อ ~6 นาที ผ่านที่ 80% SQLite

เลือกโหมด

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

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

ข้อ 1 จาก 10

What does this print?

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

C. Ann|2 Bob|0 Cy|1 The left join keeps Bob with NULL order columns. COUNT(o.id) skips NULLs, so Bob's count is 0, which is exactly what you want for "orders per customer".

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

  • Keeping unmatched rows from the left table
  • COUNT(*) vs COUNT(column) after a LEFT JOIN
  • Finding rows with no match using IS NULL
  • NULL sums and COALESCE
  • RIGHT and FULL OUTER JOIN in SQLite, MySQL and PostgreSQL

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

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

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

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

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