All quizzesMedium
Joins & Aggregations
Preview — 3 of 10 questions
What does an INNER JOIN return?
javascript
SELECT u.name, o.total
FROM users u
INNER JOIN orders o ON u.id = o.user_id;AOnly rows where there is a match in both tables
BAll rows from orders, with NULL for non-matching users
CAll rows from users, with NULL for non-matching orders
DAll rows from both tables, with NULLs for non-matches on either side
Which query finds all users, including those who have never placed an order?
javascript
-- Table users(id, name) — Table orders(id, user_id, total)ASELECT u.name, o.total FROM users u INNER JOIN orders o ON u.id = o.user_id
BSELECT u.name, o.total FROM users u LEFT JOIN orders o ON u.id = o.user_id
CSELECT u.name, o.total FROM orders o RIGHT JOIN users u ON u.id = o.user_id
DBoth B and C are correct
Which query returns the total revenue per customer?
javascript
-- Table: orders(id, user_id, total)ASELECT user_id, SUM(total) FROM orders
BSELECT user_id, SUM(total) FROM orders GROUP BY user_id
CSELECT user_id, TOTAL(total) FROM orders GROUP BY user_id
DSELECT user_id, SUM(total) FROM orders AGGREGATE BY user_id
Sign up free to play
Answer all 10 questions (7 more), see explanations for every answer, and track your score.