Hi I having a few problems what I need to do is find duplicate rows in a mssql database I can do from one table but I need it to run across 2 tables this is the code I using to do one table SELECT COUNT(*), sID1, sID2, sID3 FROM ITEM_T WHERE (sItemID = 760) OR (sItemID = 761) OR (sItemID = 762) GROUP BY sID1, sID2, sID3 HAVING COUNT(*)>1;
Ok you need also to read about the relational model (just google those terms and look for F Codd) as well as SQL syntax. Duplicates should NEVER be allowed, and databases designed with duplicate rows are bad designs and are exactly the cause of difficult query design you are now having to come up with. That's some preventative medicine for you to consider in the future when you are fully fledged database developer/administrator.
Now I'm not too sure what you are asking for. Are you saying sItemID 760 - 762 are allowed to be duplicated and ALL other sItemID's are not ?
So you want to select all duplicated sItemID's that AREN'T 760,761 or 762 ?
well of corse the person above is right. You need to create relation for the same data/columns in different tables..
But for you original implementation try this... SELECT COUNT(I.*), COUNT(B.*), I.sID1, I.sID2, I.sID3, B.sID1, B.sID2, B.sID3 FROM ITEM_T I, BANKITEM_T B WHERE (I.sItemID = 760) OR (I.sItemID = 761) OR (I.sItemID = 762) GROUP BY I.sID1, I.sID2, I.sID3 HAVING COUNT(I.*)>1 And COUNT(B.*)>1;
I hope this will work for your current situation but its very bad implementation.. Good is to use foreign keys to relate the data