Toby Derrum Toby Derrum - 6 months ago 8
SQL Question

Excluding specific record set from SQL query

I have a SQL query and wish to retrieve this data set:

SELECT
Reference, DeliveryDate, SecondaryDate, PurchaseId,
ItemDescription, Status
FROM
PLAYBOOK
WHERE
(Supplier='PLAY') AND (Status = '0')
ORDER BY
DeliveryDate DESC;


However I wish to exclude the dataset retrieved below from the first query:

SELECT
Reference, DeliveryDate, SecondaryDate, PurchaseId,
ItemDescription, Status
FROM
PLAYBOOK
WHERE
(Supplier = 'PLAY') AND (Status = '0') AND (Tax = 'Yes')
AND (Problem = 'damaged');

Answer

Can't you just use the one query:

SELECT Reference, DeliveryDate, SecondaryDate, PurchaseId,
    ItemDescription, Status,  FROM PLAYBOOK
    WHERE (Supplier='PLAY') AND (Status = '0') AND ((Tax <> 'Yes') AND (Problem <> 'damaged')) ORDER BY DeliveryDate DESC