Sql select distinct multiple columns
- distinct clause in sql
- distinct clause for multiple columns in sql
- distinct clause in sql syntax
- unique clause in sql
Having clause in sql.
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 with data in the columns , , and .
Select distinct in sql
You’d like to get a list of unique first and last names of the authors.
author_firstname | author_lastname | book_title |
---|---|---|
George | Orwell | Animal Farm |
Dan | Brown | The Davinci Code |
George | Orwell | 1984 |
Daniel | Silva | The Order |
Franz | Kafka | The Metamorphosis |
Solution:
We’ll use the SQL 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_firstname | author_lastname |
---|---|
George | Orwell |
Dan | Brown |
Daniel | Silva |
Franz | Kafka |
Discussion:
The clause is used in the statement to filter out duplicate rows in the result set.
You can use when you select a single column, or when you select multiple columns as w
- explain distinct clause in sql
- distinct clause in oracle sql