The MySQL DISTINCT clause is used to eliminate duplicate records from the table and retrieve only unique records. The MySQL DISTINCT clause is used with the SELECT statement only.
To retrieve only unique records from existing table, use the following syntax:
Parameters:
tablename: The table name from which you want to remove all records.
DISTINCT: To eliminate duplicate records.
Note:
If DISTINCT clause is used with single field, the query will return the unique values for that field only.
If DISTINCT clause is used with multiple fields, the query will retrieve unique combinations for the expressions listed.
Note:
In the above example, we have fetched unique "address" from "tblCustomerLoan"
You can use MySQL Command Line Client to fetched unique records from "tblCustomerLoan" table. It will look like this:
You can use MySQL Command Line Client to retrieve unique records for multiple fields in table. It will look like this:
You can use MySQL Command Line Client to retrieve unique records for NULL values in table. It will look like this: