Your first query will never return any rows because a single value cant possibly equal two different things. Think of it like all your criteria being tested against each row.you probably want to change your criteria to: WHERE AGTY_SYS_CD in ('ASPRS', 'APERS')Your second query would be a Self JOIN. A table joined to itself on SSN. So if you had 4 rows with the same SSN but all with different AGTY_SYS_CD values then you would bet back 12 rowsexecute this code and see what I mean:declare @t table (ssn int, agty int)insert @tselect 1,10 union allselect 1,11 union allselect 1,12 union allselect 1,13SELECT * FROM @t Z, @t A WHERE Z.ssn = A.ssn AND Z.agty <> A.agtyOUTPUT:ssn agty ssn agty----------- ----------- ----------- -----------1 10 1 111 10 1 121 10 1 131 11 1 101 11 1 121 11 1 131 12 1 101 12 1 111 12 1 131 13 1 101 13 1 111 13 1 12
Be One with the OptimizerTG