Ticker

6/recent/ticker-posts

The SQL SELECT DISTINCT Statement

The SQL SELECT DISTINCT Statement

The SQL SELECT DISTINCT Statement

The SQL SELECT DISTINCT statement is used to retrieve unique values from a column in a database table. It eliminates duplicate records and returns only distinct values.

Let's consider a sample database table called "Customers" with the following structure:

CustomerName Address City PostalCode Country
John Doe 123 Main St New York 10001 USA
Jane Smith 456 Elm St Los Angeles 90001 USA
Mark Johnson 789 Oak St London SW1A 1AA UK

Now, let's see an example of using the SELECT DISTINCT statement:

Example: Selecting Distinct Countries

To select distinct countries from the "Customers" table, you can use the following query:

SELECT DISTINCT Country FROM Customers;

This query retrieves only the unique values from the "Country" column of the "Customers" table, resulting in the following output:

Country
USA
UK

The SELECT DISTINCT statement allows you to identify and retrieve unique values from a specific column in a table. This can be helpful when analyzing data and eliminating duplicate records.

Post a Comment

0 Comments