Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I count nulls?

Status
Not open for further replies.

FranckM

Programmer
May 8, 2002
76
0
0
CA
Is it possible to count the number of null values found in one column?

Thanks for taking the time to read and answer ;)
 
select count(*) as mycount
from MyTable
where MyField is null
 
All you have to do is:

select count(*) from <table> where <column> is null

Hope this helps.
 
Odd, I get a different result with these 2 queries.

select distinct i.number, eot.sequence, eot.anotherfield, eot.description
/*select distinct count(*) as &quot;Number of rows without EOT&quot;*/

from
inst i,
inst_player ip,
ownership o,
electronic_output_title eot

where i.number = ip.number
and ip.number = o.number (+)
and o.sequence = eot.sequence (+)
and i.inst_number = '28'
and eot.myfield is null

if I change from one of the selected to an other I get 2 different results, the one that I'm using now returns 6000 some values, the other returns a number in the 15000.

can anyone see the problem here?

Thanks for taking the time to read and write ;)
 
Here's an example that may clear things:

MyTable
MyField1, Myfield2
1 B
1 C
1 D
2 A
2 A
2 C

select distinct count(*) from #MyTable
RETURNS 6 (the result set only has one row - the number field - and it's &quot;distinct&quot; among the result set)

select distinct MyField1 from #MyTable
RETURNS 2 rows (1, 2) since those are the unique occurances of the fields selected



 
Yep that was the problem, thank you very much.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top