sql server - SQL Query to find missing records between two tables that share a key -


just title asks trying find way give me number difference in transactions. question in plain english is: there bad data in database. sales transactions missing data on product , how many sold.

salestransaction (table 1) columns: transactionid, customerid, storeid, tdate

soldvia (table 2) columns: transactionid, productid, noofitems

any on appreciated. if being unclear let me know , provide more info. thank you.

this simple left join filtering nulls:

for missing items in soldvia table:

select count(*) difference  salestransaction st left join soldvia s on st.transactionid = s.transactionid  s.transactionid null 

for missing items in both tables:

select count(*) difference  salestransaction st full join soldvia s on st.transactionid = s.transactionid  st.transactionid null or s.transactionid null 

Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -