How to find the number of inconsistencies in two tables?

I have two tables: RDat1 and RDat2. I am trying to find the number of cases in which publisher_id in R1 does not match what was in publisher_id in R2, in the time interval from 2015-01 to 2015-06. I am joining two tables based on a shared key in queue_id. Here is the query I wrote, but it will always return 0 ...

Select count(*)
from RDat1 r1
join RDat2 r2 on r2.queue_id = r1.queue_id
where r1.publisher_id <> r2.publisher_id and r1.lead_time between 
'2015-01-01 00:00:00' and '2015-06-30 23:59:59' 
;
+4
source share
2 answers

Use the left outer join, not the inner join. This will return all data to r1 and null. I am r2. You can at least see all the data and if anymatch. Then you can filter if necessary

0
source
Select count(publisher_id) from RDat1 r1 where r1.publisher_id not in (select publisher_id from RDat2 r2 where r2.queue_id = r1.queue_id) and r1.lead_time between '2015-01-01 00:00:00' and '2015-06-30 23:59:59' ;
0
source

Source: https://habr.com/ru/post/1617915/


All Articles