How to filter out duplicates using Oracle’s Distinct function.
In Oracle, the DISTINCT keyword is used to return unique rows in the query results. It can be used in the SELECT statement to filter out duplicate data.
The basic syntax for using the DISTINCT keyword is as follows:
Retrieve unique values from the specified columns in the table that meet the specified condition.
In the syntax above, column1, column2,… represent the names of the columns to be returned, table_name is the name of the table to be queried, and condition is an optional WHERE clause used to filter data.
Here is an example using the DISTINCT keyword:
Choose unique departments from a list of employees.
The above example will return unique values from the department column in the employees table.
It is important to note that the DISTINCT keyword removes duplicates from all columns returned in a query. If you only want to remove duplicates from specific columns, you can simply list out the column names that need to be de-duplicated.
In addition, if the query includes aggregate functions (such as SUM, COUNT, AVG, etc.), there is no need to use the DISTINCT keyword because the aggregate function itself filters out duplicate data.