Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query Question 1

Status
Not open for further replies.

delaap

Programmer
Jun 6, 2001
22
GB
Hi,
I have a table that looks like the following:

ID
Date
Code

The primary key on the table is across ID and Date.
So the data looks like:
ID Date Code
01 01/01/2001 A
01 01/01/2002 A
01 01/01/2003 B

What I would like to return in my results set is all the records that have a date 01/01/2003 with a different code when compared to records with a date 01/01/2002.
Any ideas ?
 
select t2.* from t t1 inner join t t2
on t1.id = t2.id
and t1.date = '2002-01-01'
and t2.date = '2003-01-01'
and t1.code <> t2.code
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top