+ Reply to Thread
Results 1 to 2 of 2

Thread: Sql setting Condition

  1. #1
    Junior Member
    Join Date
    Jan 2012
    Posts
    35

    Sql setting Condition

    I have two tables client and product , i am using an inner join to compare between these tables :

    Table form :
    Code:
    idClient idProduct dateStamp
    1         1         2009-01-10
    2         1         2010-07-12
    3         1         2011-12-05
    I have used the Not in statment :
    Code:
    SELECT     products.idProduct
    FROM         products INNER JOIN
                 client ON products.idProduct = client.idProduct
    WHERE
    (products.idProduct = '1') AND (products.idProduct 
        NOT IN
        (SELECT     idProduct
        FROM          client
        WHERE      (products.idProduct = client.idProduct) AND
        (dateStamp < DATEADD(DAY, - 7, GETDATE()))))
    Any suggestion ?

  2. #2
    Junior Member
    Join Date
    Jan 2012
    Posts
    30
    In this case using the NOT EXIST is the idle solution :
    Code:
    SELECT p.idProduct
    FROM   products AS p
    WHERE  NOT EXISTS (
       SELECT *
       FROM   client AS c
       WHERE  c.idProduct = p.idProduct
       AND    c.dateStamp BETWEEN DATEADD(DAY, - 7, GETDATE()) AND GETDATE()
       )

+ Reply to Thread

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts