How to Use DISTINCT in SQL Database: Standard SQL MySQL Oracle MS SQL Server PostgreSQL Operators: DISTINCT Table of Contents Problem: Example: Solution: Discussion: Problem: You’d like to query your data to return the result without duplicate rows. Imagine you have a table with repeated entries, and you only want each unique entry to show up once. This helps in getting a cleaner and more concise set of results, making analysis easier. Example: Our database has a table named books with data in the columns author_firstname, author_lastname, and book_title. You’d like to get a list of unique first and last names of the authors. author_firstnameauthor_lastnamebook_title GeorgeOrwellAnimal Farm DanBrownThe Davinci Code GeorgeOrwell1984 DanielSilvaThe Order FranzKafkaThe Metamorphosis Solution: We’ll use the SQL DISTINCT clause to remove duplicate rows. Here’s the query: SELECT DISTINCT author_firstname, author_lastname FROM books; Here’s the result of the query: author_firstnameauthor_lastname GeorgeOrwell DanBrown DanielSilva FranzKafka Discussion: The DISTINCT clause is used in the SELECT statement to filter out duplicate rows in the result set. You can use DISTINCT when you select a single column, or when you select multiple columns as we did in our example. This is especially useful when you want to simplify your dataset and focus on unique records, making data analysis more efficient and accurate. Recommended courses: SQL Basics Standard SQL Functions SQL Practice Set Recommended articles: SQL Filtering 101 What Is a Unique Constraint in SQL? See also: How to Use SQL to Filter Your Client Email Database How Much SQL Do I Need to Know? How to Find Duplicate Rows in SQL? Subscribe to our newsletter Join our monthly newsletter to be notified about the latest posts. Email address How Do You Write a SELECT Statement in SQL? What Is a Foreign Key in SQL? Enumerate and Explain All the Basic Elements of an SQL Query