net
net

Reputation: 91

Count number of occurrences in a column?

I have a table column where the same value can be repeated in across the several rows or maybe not. I want to return a count of all the values. A structure of my table is shown below

id | name | code 
1  | xyz  | 1.1
2  | 123  | 1.1
3  | foo  | 2.1
3  | bob  | 3.1
4  | roy  | 2.1

I want to count the values in code and so in this case the result should be 3

Upvotes: 1

Views: 89

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1269693

You want to count unique values of code, as I understand the question. If so, SQL has count(distinct).

select count(distinct code)
from t;

Upvotes: 2

Related Questions