All You Need to Know About SQL Distinct Keyword

SQL stands for Structured Query Language. It is used to store, manipulate, and retrieve data present in a database server. We use the DISTINCT keyword in SQL with a SELECT statement to remove the duplicate records and return unique records. In this article, we will explore and understand the DISTINCT keyword. 

SQL DISTINCT Keyword

The DISTINCT keyword in SQL is used to fetch unique records and eliminates the duplicate records in the table. 

Syntax:

SELECT DISTINCT column1, column2,.....columnN 

FROM table_name

WHERE [condition]

Business Analyst Master's Program

Gain expertise in Business analytics toolsExplore Program
Business Analyst Master's Program

Example:

Consider the table titled CUSTOMERS” with the records below;

data

The following SQL statement selects only the DISTINCT values from the ‘city’ column:

distinct

This will produce the following result:

output-distinct

Let’s look at one more example:

ex-sql-distinct

This will produce the count of different cities in the ‘customers’ table.

output-sql-distinct

You can also select multiple columns to get unique results from them.

distinct-mutiple

output-distinct-multiple

Gain expertise in the latest Business analytics tools and techniques with the Post Graduate Program in Business Analysis. Enroll now!

Next Steps

Now that you know about the SQL DISTINCT keyword, it’s time for you to take the next step. This is an essential step to moving forward in your journey to becoming an SQL expert. If you found this article beneficial and want to get certified, check out Simplilearn’s Business Analyst Master’s Program. This comprehensive program covers SQL in-depth. Upon completion you can earn your certification in this field can jumpstart your career. 

Do you have any questions for us? Feel free to place them in the comments section of this article. We’ll get our subject experts to answer them for you ASAP.

About the Author

Aryan GuptaAryan Gupta

Aryan is a tech enthusiast who likes to stay updated about trending technologies of today. He is passionate about all things technology, a keen researcher, and writes to inspire. Aside from technology, he is an active football player and a keen enthusiast of the game.

View More
  • Disclaimer
  • PMP, PMI, PMBOK, CAPM, PgMP, PfMP, ACP, PBA, RMP, SP, and OPM3 are registered marks of the Project Management Institute, Inc.