• Articles
  • Tutorials
  • Interview Questions

SQL SELECT DISTINCT Statement - Explained

Tutorial Playlist

Introduction to SQL DISTINCT

The DISTINCT keyword in SQL is used to return unique values from a column or set of columns. This can be useful for getting a count of unique values, or for filtering out duplicate rows from a result set.

For example, let’s say we have a table of students, and we want to get a count of the number of unique students in the table. We can use the following SQL query:

SELECT COUNT(DISTINCT student_id)
FROM students;

This query will return the number 10, which is the number of unique students in the student’s table.

Wish to crack SQL job interviews? Intellipaat’s SQL Interview Questions are meant only for you!

Examples in SQL DISTINCT

Here are some other examples of how to use the DISTINCT keyword in SQL:

  • To get a list of all of the unique cities in a country, we could use the following query:
SELECT DISTINCT city
FROM countries;
  • To filter out duplicate rows from a list of products, we could use the following query:
SELECT DISTINCT product_name, product_price
FROM products;

Conclusion

The DISTINCT keyword is a powerful tool that can be used to get unique values from a column or set of columns in a SQL database. By understanding how to use the DISTINCT keyword, you can write more efficient and effective SQL queries.

Course Schedule

Name Date Details
SQL Training 16 Nov 2024(Sat-Sun) Weekend Batch View Details
23 Nov 2024(Sat-Sun) Weekend Batch
30 Nov 2024(Sat-Sun) Weekend Batch

About the Author

Data Engineer

As a skilled Data Engineer, Sahil excels in SQL, NoSQL databases, Business Intelligence, and database management. He has contributed immensely to projects at companies like Bajaj and Tata. With a strong expertise in data engineering, he has architected numerous solutions for data pipelines, analytics, and software integration, driving insights and innovation.