1

I have two columns in different product tables.

tblproduct1.partno is an old product list

tblproduct2.partno2 is a new one

Both partno columns should have identical model numbers but they don't.

When executing the below query, I get about 300 model numbers that don't match when comparing counts from both tables. tblproduct2 has 1955 records, the query below is 1638. I would expect it to return 1955.

SELECT COUNT(partno)
FROM tblproduct1
  INNER JOIN tblproduct2 ON partno = partno2

Is there a way I can list the model numbers that don't match?

2 Answers 2

2
select tblproduct1.partno from tblproduct1
   left join tblproduct2 on tblproduct1.partno = tblproduct2.partno2
   where tblproduct2.partno2 is null

shows tblproduct1.partno that have no matching tblproduct2.partno2 values

Sign up to request clarification or add additional context in comments.

2 Comments

the partno2 isn't null, it just doesn't match
sorry, I can see the query works thanks for the answer, i have asked e4c5, but I'll reinstate the question here: is there a way to see the model number? tblproduct2.partno2 returns null
0

Actually stereofrogs query is correct. It works even when the table columns are defined as 'not null' I suspect you had the two tables mixed up when you ran the query.

that is because the LEFT JOIN always has all the rows from the left table in it. If the second table does not have a matching entry it will be displayed as NULL.

So as long as you have the table with more rows as the left (or the first) table the above query will produce the desired result.

2 Comments

Yes it works, thanks for the explanation, how do I list the models in the null column? I need to compare them
you can add a second column to the query so that you have something to compare against eg: select tblproduct1.partno, tblproduct.partName ... all the best

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.