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]
Example:
Consider the table titled CUSTOMERS” with the records below;
The following SQL statement selects only the DISTINCT values from the ‘city’ column:
This will produce the following result:
Let’s look at one more example:
This will produce the count of different cities in the ‘customers’ table.
You can also select multiple columns to get unique results from them.
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.