Search code examples
sqloracleunique

How to check if all fields are unique in Oracle?


How to check if all fields are unique in Oracle?


Solution

  • SELECT myColumn, COUNT(*)
    FROM myTable
    GROUP BY myColumn
    HAVING COUNT(*) > 1
    

    This will return to you all myColumn values along with the number of their occurence if their number of occurences is higher than one (i.e. they are not unique).

    If the result of this query is empty, then you have unique values in this column.