Search code examples
sqlsql-serverdistinct

Select Distinct for 2 columns in SQL query


If I have a table such as

1 bob
1 ray
1 bob
1 ray
2 joe
2 joe

And I want to select distinct based on the two columns so that I would get

1 bob
1 ray
2 joe

How can I word my query? Is the only way to concatenate the columns and wrap them around a distinct function operator?


Solution

  • select distinct id, name from [table]
    

    or

    select id, name from [table] group by id, name