How do you use the DISTINCT keyword in SQL?

In SQL, the DISTINCT keyword is used to select unique values from a result set.

The basic syntax for using the DISTINCT keyword is as follows:

SELECT DISTINCT column1, column2, ...
FROM table_name;

In this syntax, you can specify the columns for which you want to select unique values, separated by commas. The query will return the unique values in the specified columns.

Here is an example query using DISTINCT:

SELECT DISTINCT city FROM customers;

This query will select unique city values from the customers table.

Please note that the DISTINCT keyword removes duplicate rows, not duplicate values in a specific column. If you only want to remove duplicate values in a specific column, you can select only that column.

bannerAds