I am trying to form a sql statement which checks for duplicated userids WITHIN TABLE1 and TABLE2 (Duplicated userids found by joining Table1 and Table2 together should not be recorded.)
Below are my table information and the current checks that I have implemented:
Table1: UserID, Username.
Table2: UserID, Status.
Table3: UserID, Username, Issue
Currently I only have 3 SELECT statement which fulfills the above 3 checks and INSERT the result into Table3:
1.
Insert in to Table3(userid,issue)
SELECT t1.userid,'check no.1'
FROM table1 t1
FULL OUTER JOIN table2 t2 ON t1.userid = t2.userid
where t1.userid not null and t2.userid is null
2.
Insert in to Table3(userid,issue)
SELECT t1.userid,'check no.2'
FROM table1 t1
inner JOIN table2 t2 ON t1.userid = t2.userid
where t2.status = 'DELETE'
3.
Insert in to Table3(userid,issue)
SELECT t2.userid,'check no.3'
FROM table2 t2
right outer JOIN table2 t2 ON t1.userid = t2.userid
where t2.status <> 'DELETE' and t1.userid is null
Now, I want a 4th sql query which checks for duplicated UserID in both Table1 and Table2 within themself, not by comparing 2 tables together, but each tables individually.
If any duplicate is found, insert the record into Table3 with
ISSUE= ‘Duplicated User ID found in Table1‘, and
ISSUE= ‘Duplicated User ID found in Table2‘
Thank you guys.
From your question the answer should be:
However I’m not sure if you want to archieve something else.