Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Distinct with select *

Tags:

sql

Is it possible to use select * with distinct or write easily something that has the same impact?

I need to select all columns from a table with distinct value, but listing all the columns in select clause would be nerve-breaking because the number of columns is over 20!

like image 754
jaana Avatar asked Dec 22 '22 22:12

jaana


2 Answers

In Microsoft SQL Server you can write:

select distinct * from MyTable

However, it is considered "best practice" to specify the columns explicitly, partly because it improves the performance of the query, but also to protect yourself from failures that would arise if the database schema were to change in the future

like image 53
John Sibly Avatar answered Jan 07 '23 10:01

John Sibly


This should work:

SELECT DISTINCT * FROM TABLE_NAME
like image 26
codaddict Avatar answered Jan 07 '23 08:01

codaddict