mysql - SQL Compare rows -
okay here situation: following data in table.
pair_no no no2 3 5678efgh 1234abcd 4 1111bbbb 0000aaaa 1 1234abcd 5678efgh 2 0000aaaa 1111bbbb the constraints if no = no2 in row skip row. in sample data rows selected should pair no 3 , 4.
i have tried merge , inner join self keep getting 4 rows back.
i have tried insert table not exists again 4 rows inserted.
select a.* pairs inner join pairs b on a.no=b.no2 , a.no2=b.no; i thinking maybe selecting distinct number column 1 , check in column 2 think yield same 4 rows.
i may on thinking problem , maybe here can @ , see solution hiding.
i testing on mysql should run on sqlserver 2008. have searched questions didn't seem match data set issue.
taking @ word, meaning selecting records value of no column not appear anywhere in no2 column in same table, try this:
select a.pair_no, a.no, a.no2 pairs left join pairs b on(a.no = b.no2) b.pair_no null -- assuming column not nullable another option use not exists:
select pair_no, no, no2 pairs not exists( select 1 pairs b b.no2 = a.no ) i prefer left join option since it's shorter , more readable.
both of these statement should work on both mysql , sql server.
Comments
Post a Comment