Nomad
Nomad

Reputation: 643

Getting unique combinations in an SQL table

I have an SQL table that looks like this

122014 MPE140 TFE1 50000 2014-2015
141432 MPE140 TFE1 50000 2014-2015
132657 MPE140 TFE1 50000 2014-2015

131922 MPE129 TFE1 40000 2014-2015
141108 MPE129 TFE1 40000 2014-2015
122177 MPE129 TFE1 40000 2014-2015

141156 MPE132 TFC1 50000 2014-2015
111339 MPE132 TFC1 50000 2014-2015
141012 MPE132 TFC1 50000 2014-2015

140596 MPE140 TFC1 40000 2014-2015
142732 MPE140 TFC1 40000 2014-2015
140943 MPE140 TFC1 40000 2014-2015

140596 MPE140 TFC1 40000 2013-2014
142732 MPE140 TFC1 40000 2013-2014
140943 MPE140 TFC1 40000 2013-2014

and I need a query to select rows that would look something like this:

MPE140 TFC1 40000 2013-2014
MPE140 TFE1 50000 2014-2015
MPE129 TFE1 40000 2014-2015
MPE132 TFC1 50000 2014-2015
MPE140 TFC1 40000 2014-2015

is this even possible?

Upvotes: 0

Views: 60

Answers (2)

Steve
Steve

Reputation: 551

You could also use a GROUP BY if you want to know the number of records for each unique combination:

select count(*) as Combination_Count, column2, column3, column4, column5
from YOUR_TABLE
Group by column2, column3, column4, column5

Upvotes: 0

neshkeev
neshkeev

Reputation: 6486

Since you didn't provide any info about the structure of your table:

select DISTINCT column2, column3, column4, column5
  from YOUR_TABLE

I don't use column1 because it obviously has unique values.

Upvotes: 1

Related Questions