How do you use the SELECT DISTINCT statement in SQL?

In SQL, the SELECT DISTINCT statement is used to select unique values from the database. The syntax is as follows:

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

column1, column2, etc. are the names of the columns to be selected and you can choose multiple columns. table_name is the name of the table to be selected.

For example, if there is a table named “customers” with a column named “country”, you can use the following statement to select the unique country names from that table:

SELECT DISTINCT country
FROM customers;

This will return the unique country names in the customers table.

Leave a Reply 0

Your email address will not be published. Required fields are marked *


广告
Closing in 10 seconds
bannerAds