Pages

Wednesday, March 18, 2015

NOT IN CONDITION RETURNS EMTPTY RESULT SET

NOT IN query returns the empty result means NULL value exist in the list of the SubQuery.You need explicitly exclude them using IS NOT NULL Syntax.

SELECT *
FROM PurchaseOrder 
WHERE PurchaseOrderID NOT IN ( SELECT  PurchaseOrderID FROM PurchaseOrderDetail
WHERE PurchaseOrderID IS NOT NULL )

Reason behind writing IS NOT NULL condition in Subquery is that It will evaluate the expression based truth tables.In NULL condition what will happen the expression is Unknown state. It will ignore other records also.

No comments:

Post a Comment