Link to home
Start Free TrialLog in
Avatar of sath350163
sath350163

asked on

Query to fetch rows with matching values for just few columns column as a single row

Hello,
I have a table with rows having same id and code value, but different Effective date.
Id         Code          EffectiveDate     cost
1          basic          01-jan-2010        5.00
1          basic          06-feb-2011        5.00
1          exclusive    09-aug-2012        15.00

Open in new window


My query needs to return only 2 rows, one for 1 basic, and another for 1 exclusive.
Result should be like:
Id            Code                 cost
1              Basic                5.00
1              Exclusive          15.00

Open in new window


DISTINCT would not work as the Effective date is different between the two records with Id=1 and Code = 'Basic'.

Thanks!
SOLUTION
Avatar of Scott Pletcher
Scott Pletcher
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
select distinct id, code, cost
from YourTable
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial