Is there a way to count the number of different values?

In PostgreSQL 9.4, I have a table:

id         p_id
PK        integer
-----------------
1           1
2           1
.............
123122       2233

      

Is there a way to count all the different values p_id

in a table with just one query ( without using subqueries ). I can use any window function.

+3


source to share


1 answer


You can use a modifier distinct

in a function count

:



SELECT COUNT(DISTINCT p_id) FROM mytable

      

+3


source







All Articles