SELECT DISTINCT with ORDER BY Clause
In this example, we are going to display all the distinct data from multiple columns of our table in descending order. We will use ORDER BY Clause along with DESC keyword to achieve this task.
Query:
SELECT DISTINCT score, course
FROM w3wiki
ORDER BY score DESC;
Output:
Explanation: In the above image, we can clearly see that all the data in the result table are unique/ distinct. We can notice that the data is sorted in descending order with respect to score column. We can see that score 150 comes first, followed by 100 then 50.
How to SELECT DISTINCT on Multiple Columns in SQL?
In the world of databases, data duplication can lead to confusion and inefficiency. SQL provides a powerful tool, SELECT DISTINCT, to retrieve unique values from columns. However, when dealing with multiple columns, the approach becomes more detailed.
In this article, We will explore How to SELECT DISTINCT on multiple columns in SQL by understanding various methods along with the practical implementation and so on.