sql - Comparing two tables and get the values that dont match -
i have 2 tables articles.
table 1 article
, table 2 articlefm
both tables have 1 field artnr
.
'table 1' has 2192 artnr
, 'table 2' has 2195 artnr
.
i want in query find out whats artnr
of 3 articles not matched.
if 'table 2' has more articles 'table 1' need list artnr
.
how can create this?
you can using full join
:
select coalesce(t1.artnr, t2.artnr) artnr, case when t1.artnr null 'table1' else 'table2' end missingfrom table1 t1 total bring together table2 t2 on t1.artnr = t2.artnr t1.artnr null or t2.artnr null;
note, because there difference in count of 3, not mean there 3 records in 1 table missing other. imagine following:
table1 table2 ------ ------- 1 2 2 4 3 6 4
the difference in count 1, there 2 records nowadays in table1 aren't in table2, , 1 in table2 isn't in table1. using above total bring together method result like:
artnr | missingfrom ------+------------- 1 | table1 3 | table1 6 | table2
sql
No comments:
Post a Comment