If this is your first visit, be sure to check out the FAQ by clicking the link above.
You may have to register before you can post: click the register link above to proceed.
To start viewing messages, select the forum that you want to visit from the selection below.
assume STATUS='I' means inactive (this was my best guess, based on your information)
Code:
select ID
, ADDTYPE
, SEQNUM
, STATUS
, STREET1
from yourtable as o
where STATUS <> 'I' /* check this */
and ADDTYPE =
( select max(ADDTYPE)
from yourtable
where ID = o.ID
and STATUS = o.STATUS )
SELECT o.*, i.*
FROM ADD_INFO AS o
LEFT OUTER JOIN ADD_INFO AS i
ON o.IDNUM = i.IDNUM
AND o.ADDTYPE <> i.ADDTYPE
WHERE i.ADDTYPE IS NULL
OR o.ADDTYPE > i.ADDTYPE
AND o.STATUS <> 'I'
Here's your parentheses ... and it's tested... but still if you are getting different result let me know... it will be good thing to learn... that's why we are here .. !
SELECT o.*, i.*
FROM ADD_INFO AS o
LEFT OUTER JOIN ADD_INFO AS i
ON o.IDNUM = i.IDNUM
AND o.ADDTYPE <> i.ADDTYPE
WHERE (i.ADDTYPE IS NULL
OR o.ADDTYPE > i.ADDTYPE)
AND o.STATUS <> 'I'