I have a really hard time to understand the difference between these two queries. The don't give the same output, just a slightly difference in the results. Isn't these two queries the same, but just inverted? You can see the difference in the last subquery.
SELECT *
FROM[dbo].[MNO International AB$Item] t1
WHERE
t1.[Item Type] = 0
AND (
NOT EXISTS(SELECT * FROM [dbo].[MNO International AB$Item Cross Reference] t2 WHERE t2.[Item No_] = t1.No_ AND t2.[Cross-Reference Type No_] = 'EAN13' AND t2.[Cross-Reference No_] <> '' AND t2.[Cross-Reference Type] = 3)
OR t1.[Statistics Group] = 0
) --Result: 2178
AND NOT EXISTS
(SELECT * FROM [dbo].[MNO International AB$Master] t2
WHERE t1.[Master No_] = t2.No_
AND t2.[Collection No_] LIKE 'NEW-NOS'
)
The other Query
SELECT *
FROM[dbo].[MNO International AB$Item] t1
WHERE
t1.[Item Type] = 0
AND (
NOT EXISTS(SELECT * FROM [dbo].[MNO International AB$Item Cross Reference] t2 WHERE t2.[Item No_] = t1.No_ AND t2.[Cross-Reference Type No_] = 'EAN13' AND t2.[Cross-Reference No_] <> '' AND t2.[Cross-Reference Type] = 3)
OR t1.[Statistics Group] = 0
) --Result: 2178
AND EXISTS
(SELECT * FROM [dbo].[MNO International AB$Master] t2
WHERE t1.[Master No_] = t2.No_
AND t2.[Collection No_] NOT LIKE 'NEW-NOS'
)