#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2012
    Posts
    4
    Rep Power
    0

    Filtering Multiple records IF they have been inputed in the last 12 months


    OK, another question! I am trying to pull records 12-18 months old for appointments. The catch is there can't be any other records for an appointment within the last 12 months. How can I filter out these records? I should say each appointment has it's own record, but shares a Key.
  2. #2
  3. SQL Consultant
    Devshed Supreme Being (6500+ posts)

    Join Date
    Feb 2003
    Location
    Toronto Canada
    Posts
    27,140
    Rep Power
    4274
    Code:
    SELECT ...
      FROM daTable AS t
     WHERE somedate ... -- 18 to 12 months ago
       AND NOT EXISTS
           ( SELECT 1
               FROM daTable
              WHERE sharedkey = t.sharedkey
                AND somedate ... -- 12 to 0 months ago  )
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

IMN logo majestic logo threadwatch logo seochat tools logo