views:

29

answers:

1

Hi,

I would like to know if there is any way of counting the number of tuples in a table without actually using the COUNT function?

A             B         C
XXXX         YYYY       IIII
XXXX         SSSS       PPPP
RRRR         TTTT       FFFF
KKKK         AAAA       BBBB

If I would like to know how many times XXXX has appeared without using COUNT. Is is possible?

+3  A: 

Does this count?

SELECT SUM(1) AS COUNT
  FROM SomeTable
 WHERE A = 'XXXX';

Or, if 'XXXX' can appear in the other columns:

SELECT SUM(1) AS COUNT
  FROM SomeTable
 WHERE (A = 'XXXX' OR B = 'XXXX' OR C = 'XXXX');
Jonathan Leffler
What an answer! Can you explain what does sum(1) do?
Sana
Sum(1) sums 1 for each record that complies with the where conditions. Basically it is the same as Sum(column_name) but using a constant.
Guillem Vicens