Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to count unique rows in Oracle

Tags:

I have an oracle database table with a lot of columns. I'd like to count the number of fully unique rows. The only thing I could find is:

SELECT COUNT(DISTINCT col_name) FROM table; 

This however would require me listing all the columns and I haven't been able to come up with syntax that will do that for me. I'm guessing the reason for that is that this query would be very low performance? Is there a recommended way of doing this?

like image 456
mck Avatar asked Oct 23 '14 22:10

mck


People also ask

How do I count unique rows in a table?

We can use SQL Count Function to return the number of rows in the specified condition. The syntax of the SQL COUNT function: COUNT ([ALL | DISTINCT] expression); By default, SQL Server Count Function uses All keyword.

How do I count distinct values in SQL Developer?

Using COUNTDISTINCT to get the number of distinct values for an attribute. The COUNTDISTINCT function returns the number of unique values in a field for each GROUP BY result. COUNTDISTINCT can only be used for single-assign attributes, and not for multi-assigned attributes.

What does count (*) do in Oracle?

COUNT(*) function returns the number of items in a group, including NULL and duplicate values. COUNT(DISTINCT expression) function returns the number of unique and non-null items in a group. COUNT(ALL expression) evaluates the expression and returns the number of non-null items in a group, including duplicate values.

How do I count rows in PL SQL?

%ROWCOUNT yields the number of rows affected by an INSERT , UPDATE , or DELETE statement, or returned by a SELECT INTO statement. %ROWCOUNT yields 0 if an INSERT , UPDATE , or DELETE statement affected no rows, or a SELECT INTO statement returned no rows.


1 Answers

How about

SELECT COUNT(*)  FROM (SELECT DISTINCT * FROM Table) 
like image 136
okaram Avatar answered Sep 18 '22 14:09

okaram