This query returns all of the selected values from today's date to 90 days ago:
 SELECT max(cases_visits.created_dt), users_profiles.account_num,
    concat(cases.patient_first_initial,
    cases.patient_middle_initial, cases.patient_last_initial) AS initials,
    concat(users.first_name, ' ',users.last_name) as name   
    FROM cases
    JOIN users_profiles
    ON users_profiles.user_id=cases.doctor_id
    JOIN cases_visits
    ON cases.id=cases_visits.case_id
    join users on users.id = cases.doctor_id
    WHERE cases_visits.patient_visit_type = 'NP' && cases_visits.created_dt BETWEEN     curdate() - INTERVAL 90 DAY AND SYSDATE()
    group by users.first_name
I'd like to find a query that will now select the exact same thing, but only if records DO not exist in the previous query. EXAMPLE: return records from > 90 days ago, that do not have records in the past 90 days.
I have tried to do this: (note, 2013-07-03 in the query was 90 days from the first time i ran)
    SELECT cases_visits.created_dt, users_profiles.account_num,
    concat(cases.patient_first_initial,
    cases.patient_middle_initial, cases.patient_last_initial) AS initials,
    concat(users.first_name, ' ',users.last_name) as name
    FROM cases
    JOIN users_profiles
    ON users_profiles.user_id=cases.doctor_id
   JOIN cases_visits
   ON cases.id=cases_visits.case_id
   join users on users.id = cases.doctor_id
   WHERE cases_visits.created_dt < '2013-07-03'
   group by users.first_name
This does not give me the proper data, I think because i need to somehow exclude records that exist from the past 90 days.
THIS IS WHAT IM TRYING TO DO: Select a records with a a value = to 'NP' for the past 90 days, then i need to select records where there is not a np value for greater than 90 days, but these records should be completely unique from the first query (i.e the individual could have a case from within the 90 days, and one 180 days ago, i would not need his records.)
EDIT: I forgot to mention I have tried this query with an error near 'in':
SELECT cases_visits.created_dt, users_profiles.account_num,
concat(cases.patient_first_initial,
cases.patient_middle_initial, cases.patient_last_initial) AS initials,
concat(users.first_name, ' ',users.last_name) as name    
FROM cases 
JOIN users_profiles
ON users_profiles.user_id=cases.doctor_id    
JOIN cases_visits
ON cases.id=cases_visits.case_id    
join users on users.id = cases.doctor_id    
WHERE cases_visits.created_dt < '2013-07-03'
and cases_visits.patient_visit_type = 'NP'    
and not in (select created_dt from cases_visits where  cases_visits.patient_visit_type = 'NP' && cases_visits.created_dt BETWEEN curdate() - INTERVAL 90 DAY AND SYSDATE())   
group by users.first_name
 
     
     
     
    