Home » SQL & PL/SQL » SQL & PL/SQL » Count of unique values of a field in a table.
Count of unique values of a field in a table. [message #38863] Wed, 22 May 2002 13:46 Go to next message
Al Webre
Messages: 2
Registered: May 2002
Junior Member
I know I've seen how to do this somewhere before - but can't think of the right combination to get it. I have FIELD1 in TABLE1.
I can do select unique FILED1 from TABLE1; and get 5 separate values.

I can also select count (*) from TABLE1; and get 53,276, the number of rows in the table.

I want to count the number of unique entries for FILED1 in TABLE1. I haven't been able to do it.

The output should look something like
Value1 300
Value2 277
Value3 23555
Value4 4866
Value5 333

Does anybody know how to construct the PL/SQL statement to do this?
Re: Count of unique values of a field in a table. [message #38864 is a reply to message #38863] Wed, 22 May 2002 15:19 Go to previous messageGo to next message
Todd Barry
Messages: 4819
Registered: August 2001
Senior Member
select field1, count(*)
  from table1
 group by field1;
Re: Count of unique values of a field in a table. [message #38882 is a reply to message #38863] Thu, 23 May 2002 10:36 Go to previous messageGo to next message
Mas
Messages: 1
Registered: May 2002
Junior Member
Select distinct(field1),count(field1)
from table1
group by field1
Re: Count of unique values of a field in a table. [message #38884 is a reply to message #38863] Thu, 23 May 2002 11:32 Go to previous message
Todd Barry
Messages: 4819
Registered: August 2001
Senior Member
Adding a distinct clause here is really superfluous when the query is already grouped by that column.
Previous Topic: CREATING A NEW SCHEMA?
Next Topic: inserting data into single table from multiple tables
Goto Forum:
  


Current Time: Tue May 21 18:43:44 CDT 2024