mevr
mevr

Reputation: 1125

Distinct not working as expected with sql

How does distinct work with the following table:

id  | id2    | time
-------------------
1   | 5555 | 12
2   | 5555 | 12
3   | 5555 | 33
4   | 9999 | 44
5   | 9999 | 44
6   | 5555 | 33

select distinct * from table

Upvotes: 1

Views: 1538

Answers (3)

John Cappelletti
John Cappelletti

Reputation: 81960

Select Distinct ID2 From SomeTable

Will return 5555 9999

Upvotes: 1

ScaisEdge
ScaisEdge

Reputation: 133370

If you use select distinct * from table all the row are distinct

if you use

 select distinct id2  , time from table

then you obtain

    id2 | time

   5555 | 12
   5555 | 33
   9999 | 44

With distinct you obtain the distinct rows based on the result of the select

Upvotes: 3

Mureinik
Mureinik

Reputation: 311308

Each row here is different, so distinct will have no visible effect, and all the rows will be returned.

Upvotes: 1

Related Questions