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?
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.
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.
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.
%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.
How about
SELECT COUNT(*) FROM (SELECT DISTINCT * FROM Table)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With