Created
November 27, 2012 21:43
-
-
Save btedev/4157285 to your computer and use it in GitHub Desktop.
MySQL temp table example for missing values
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
create table pantry(name varchar(50), quantity int); | |
insert into pantry values('soup', 10), ('celery', 5), ('crackers', 2); | |
create temporary table shopping_list(name varchar(50)); | |
insert into shopping_list values ('soup'), ('onion'), ('celery'); | |
select a.name, ifnull(b.quantity, 0) as quantity | |
from shopping_list a | |
left join pantry b on a.name = b.name; | |
+--------+----------+ | |
| name | quantity | | |
+--------+----------+ | |
| soup | 10 | | |
| onion | 0 | | |
| celery | 5 | | |
+--------+----------+ | |
3 rows in set (0.00 sec) | |
drop table shopping_list; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment