What does a view store?
- Query text, fresh each use
- A frozen copy of the rows
- A copy of the rows, refreshed once a day
Which clause tests that no matching rows occur?
- ORDER BY
- NOT EXISTS
- GROUP BY
Two lists each contain 1 and 2. UNION of the two lists returns 1 and 2, once each.
Circle one: True False
What is the second way to list customers who never ordered?
- SELECT name FROM Customers c LEFT JOIN Orders o ON o.customer_id = c.id WHERE o.customer_id IS NULL
- SELECT name FROM Customers c INNER JOIN Orders o ON o.customer_id = c.id
- UNION customers with orders
Which query lists customers who never ordered?
- SELECT name FROM Customers WHERE id IN (SELECT customer_id FROM Orders)
- SELECT name FROM Orders WHERE total > 0
- SELECT name FROM Customers c WHERE NOT EXISTS (SELECT 1 FROM Orders o WHERE o.customer_id = c.id)
List customers who never ordered, matching orders by customer id. Orders hold one NULL customer id. Which form still answers correctly?
- NOT IN, since it ignores NULL customer ids
- NOT EXISTS, NULL never matches
- NOT IN, since it treats NULL as a match
CREATE VIEW NeverShipped AS SELECT name FROM Suppliers s WHERE NOT EXISTS (SELECT 1 FROM Shipments h WHERE h.supplier_id = s.id) defines a view that later queries can use as a table.
Circle one: True False
A join version returns one customer three times, the EXISTS version once. Why?
- EXISTS returns one row for every match
- The join removes duplicate customers
- Join fans out rows