If I understood you correctly you are comparing Record_ID to Phase_ID try this:
SELECT rx.* FROM records rr LEFT JOIN records rx ON rr.Record_ID=rx.Phase_ID WHERE rr.Record_Date>@date1 && rr.Record_Date<@date2 && NOT (rx.Record_Date>@date3 && rx.Record<@date4); This assumes that @date1, @date2, @date3, @date4 contain your date values For my tests, I used: @date1:="2001-01-13"; @date2:="2001-01-15"; @date3:="2000-12-31"; @date4:="2001-01-02"; -----Original Message----- From: John Rosendahl [mailto:[EMAIL PROTECTED]] Sent: Friday, February 08, 2002 12:53 PM To: [EMAIL PROTECTED] Subject: Exclusion Query help I am trying to run a query I have a table Records ---------------------------- |Record_ID | |Phase_ID | |Record_Date | ---------------------------- I need to find the records that have a record date between date1 and date 2 but exclude the records with a matching Phase_ID that opccured between date3 and date 4 so if I had the following table Record_ID Phase_ID Record_Date 1 1 1/01/01 2 3 14/01/01 3 1 14/01/01 I would want want the query to return only Record number 2 (Given that 1/01/01 is between date 3 & 4 and 14/01/01 is between date 1 & 2) Does anyone know how to do this? mySQL, SQL --------------------------------------------------------------------- Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail <[EMAIL PROTECTED]> To unsubscribe, e-mail <[EMAIL PROTECTED]> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php --------------------------------------------------------------------- Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail <[EMAIL PROTECTED]> To unsubscribe, e-mail <[EMAIL PROTECTED]> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php --------------------------------------------------------------------- Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail <[EMAIL PROTECTED]> To unsubscribe, e-mail <[EMAIL PROTECTED]> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php