Querying Two Tables For Duplicate Values

Viewed 49161

I have a stored procedure which moves (or ought to) records from one table to another. However I now want to create a procedure that checks the data in 'TableA' against the data in 'TableB'

SELECT A.Num, B.Num
FROM TableA AS A 
LEFT JOIN TableB AS B ON A.Num = B.Num
WHERE B.Num IS NULL

Basically, I want to pull out any number which isn't in 'TableB' but is in 'TableA', is a LEFT JOIN the way to do this? I have been unsuccessful in locating missing files so far, and I have removed some to form a test case.

5 Answers
Finding duplicates between two table
select table1.column_name, count(*) from table_name table1
inner join table_name table2
ON table1.coumn_name = table2.column_name;
ex:
SELECT u.username  FROM users u
INNER JOIN src_users ud
ON u.username = ud.username;
Finding duplicates in single table
select username, count(*) from users group by username having count(*) >1;
Related