Sana
Sana

Reputation: 9915

count number of tuples without COUNT. Is it possible?

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?

Upvotes: 1

Views: 512

Answers (1)

Jonathan Leffler
Jonathan Leffler

Reputation: 754700

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');

Upvotes: 3

Related Questions