jaana
jaana

Reputation: 295

Distinct with select *

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!

Upvotes: 4

Views: 2133

Answers (4)

Ali Shah Ahmed
Ali Shah Ahmed

Reputation: 3333

Adding the "distinct" keyword right after "select" does the work. For example:

SELECT DISTINCT * FROM TABLE_NAME

Upvotes: 0

user1421044
user1421044

Reputation:

Use this query:

SELECT DISTINCT Employee, Rank
FROM Employees

Upvotes: 1

John Sibly
John Sibly

Reputation: 23076

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

Upvotes: 7

codaddict
codaddict

Reputation: 455152

This should work:

SELECT DISTINCT * FROM TABLE_NAME

Upvotes: 3

Related Questions