Skip to content
Advertisement

SQL NOT EXIST returning duplicate value in query results

Hi Seem to be getting duplicates from this sql code it suppose to find records on BO Data that is not on Order Data by using the following as a key Keyorderstatus all my query results are on the Order Data already, How can a remedy this issue?

Advertisement

Answer

As @dfundako said – hard to check without data tables to test against.

I’m thinking this SQL should do what you’re after:

Checking [Order Data].KeyOrderStatus IS NULL may not be necessary as (I’m assuming) [BO Data].KeyOrderStatus is a Primary Key so it must always contain a value and the SQL checks if that’s different from the value in [Order Data] – if it’s NULL it will be different from the PK.

Edit: I’ve added in the other fields not relevant to the joins. You’ll have to group on these to.

Advertisement