All pastes #551261 Raw Edit

Miscellany

public text v1 · immutable
·published 2007-06-08 18:47 UTC
rendered paste body
mysql> create table channel (channel int);
Query OK, 0 rows affected (0.01 sec)

mysql> create table favorite_channel(name varchar(35), favorite_channel int);
Query OK, 0 rows affected (0.01 sec)

mysql> insert into channel (channel) values (1), (2), (3), (4), (5);
Query OK, 5 rows affected (0.01 sec)
Records: 5  Duplicates: 0  Warnings: 0

mysql> insert into favorite_channel (name, favorite_channel) values ('Eric', 2), ('Lance', 1), ('DannyB', 4);
Query OK, 3 rows affected (0.00 sec)
Records: 3  Duplicates: 0  Warnings: 0

mysql> select channel, count(favorite_channel) from channel left join favorite_channel on channel.channel = favorite_channel.favorite_channel group by channel;
+---------+-------------------------+
| channel | count(favorite_channel) |
+---------+-------------------------+
|       1 |                       1 |
|       2 |                       1 |
|       3 |                       0 |
|       4 |                       1 |
|       5 |                       0 |
+---------+-------------------------+
5 rows in set (0.00 sec)