LEFT JOIN in SQL
Level 3109 keystrokes
LEFT JOIN returns all rows from the left table and matched rows from the right.
SQL code
-- Show each user's name and the total of their order1SELECT2 users.name,3 orders.total4FROM5 users-- LEFT JOIN keeps every row of users, even without a matching order6LEFT JOIN -- For a user with no order (Carol), orders.total is NULL7 orders ON users.id = orders.user_id-- Sort the rows alphabetically by user name8ORDER BY9 users.name;Output
+-------+-------+ | name | total | +-------+-------+ | Alice | 99.50 | | Bob | 75.25 | | Carol | NULL | +-------+-------+ 3 rows in set
Practice typing this code. Results are not recorded in the rankings.
Symbols in this code
The symbols you type in this SQL code and how often they appear.
.× 5_× 1,× 1;× 1=× 1