count() in mysql

February 9th, 2009 | Categories: Boring | Tags:

it’s a little different from oracle in mysql when deal with NULL.

mysql> use test;
Database changed
mysql> create table diffcount(id char(8));
Query OK, 0 rows affected (0.01 sec)

mysql> insert into diffcount values(’hello’);
Query OK, 1 row affected (0.00 sec)

mysql> insert into diffcount values(’world’);
Query OK, 1 row affected (0.00 sec)

mysql> insert into diffcount values(null);
Query OK, 1 row affected (0.00 sec)

mysql> insert into diffcount values(’count’);
Query OK, 1 row affected (0.00 sec)

mysql> show create table  diffcount;
+———–+———————————————————————————————–+
| Table     | Create Table                                                                                  |
+———–+———————————————————————————————–+
| diffcount | CREATE TABLE `diffcount` (
`id` char(8) default NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 |
+———–+———————————————————————————————–+
1 row in set (0.00 sec)

mysql> select * from diffcount;
+——-+
| id    |
+——-+
| hello |
| world |
| NULL  |
| count |
+——-+
4 rows in set (0.00 sec)

mysql> select count(*) from diffcount;
+———-+
| count(*) |
+———-+
|        4 |
+———-+
1 row in set (0.00 sec)

mysql> select count(id) from diffcount;
+———–+
| count(id) |
+———–+
|         3 |
+———–+
1 row in set (0.00 sec)

Del.icio.us Google书签 Digg Live Bookmark Technorati Furl Yahoo书签 Facebook 百度搜藏 新浪 ViVi 365Key 网摘 天极网摘 和讯网摘 博拉网 POCO 网摘 饭否 QQ 书签 Digbuzz 我挖网 Mister Wong
  1. OurMySQL
    February 10th, 2009 at 12:50
    #1