SELECT COUNT in Database
By admin on Oct 21, 2008 in database
This is a common problem often overlooked by Java programmer.
Create the following table in your database
1: create table test_table
2: (
3: field_1 varchar2(10) not null,
4: field_2 varchar2(10)
5: );
6:
7:
8: insert into test_table values('1','1');
9:
10: insert into test_table values('2', null);
Do
select count(*) from test_table
The number of records = 2
Do
select count(field_1) from test_table
The number of records = 2
Do
select count(field_2) from test_table
The number of records = 1. This is because it has NULL value in the 2nd record
Same for
select count(distinct field_2) from test_table
NULL value is excluded.
Sorry, comments for this entry are closed at this time.