I have the following table: compare. I need to do an inner join with a products table:
idCompare idProduct dateStamp
1 1 2011-12-12
2 1 2011-12-10
3 1 2012-01-05
I want to exclude the idproduct’s from my results if any of them have a date within say 7 days.
I’ve tried using the NOT IN and NOT EXISTS without success
SELECT products.idProduct
FROM products INNER JOIN
compare ON products.idProduct = compare.idProduct
WHERE
(products.idProduct = '1') AND (products.idProduct
NOT IN
(SELECT idProduct
FROM compare
WHERE (products.idProduct = compare.idProduct) AND
(dateStamp < DATEADD(DAY, - 7, GETDATE()))))
Could look like this:
Don’t
JOINto the tablecomparein addition. Checking withNOT EXISTSis enough according to your description.