Question : Distinct on multiple columns

I have checked a few online posts but cant get my issue solved.

I need 2 tables
1 table I already have and it is a listing of clients and their products the other table is based on Table1 but only shows distinct combinations for each product

I have an existing table called Table1 below

ClientID  Product1 Product2 Product3
100        1
101        1
102        1              1
103        1              1
104        1              1             1
105        1              0             1


Table2 needs to look like below - only shows distinct combinations of product:
I dont know if possible to do this directly using SQL or if another table has to be created?

ClientID  Product1 Product2 Product3
100        1
102        1              1
104        1              1             1
105        1              0             1

one way I thought is to create another table of just distinct combinations e.g. below, then join this table to table1 matching each Product e.g. table1.Product1 = table2.Product1 etc


Product1 Product2 Product3
 1
 1              1
 1              1             1
 1              0             1

please let me know if a better way?


Answer : Distinct on multiple columns

You can use

select min(clientID) as ClientID, Product1, Product2, Product3
from table1
Group by Product1, Product2, Product3

If you need to create a table from the select, then

select min(clientID) as ClientID, Product1, Product2, Product3
into table2
from table1
Group by Product1, Product2, Product3
Random Solutions  
 
programming4us programming4us