// hmmm ... this statement to find matches between teachers and schools based on criteria such as location, // arrival, status and whether that match had been perviously made and stored in the sent_match table. // any matches sent between school and teacher would get stored in sent match. // Syntaxically, can this statement be used to find matches that HAVEN'T appeared already in the sent_match table? // I'm thinking the right/left joins make this impossible .. SELECT teachers.name, teachers.arrival AS teachers_arrival, teachers.location, school_jobs.school_jobs_id, sent_match.job_id, school_jobs.school, school_jobs.city, school_jobs.arrival AS school_jobs_arrival, teachers.teacher_id, teachers.status, school_jobs.status FROM school_jobs LEFT JOIN sent_match ON school_jobs.school_jobs_id = sent_match.job_id RIGHT JOIN teachers ON sent_match.teacher_id = teachers.teacher_id WHERE teachers.arrival BETWEEN school_jobs.arrival -2 AND school_jobs.arrival +2 AND ( teachers.location = school_jobs.city OR teachers.location = '1' ) AND teachers.status != -1 AND school_jobs.status != -1 AND ( teachers.teacher_id != sent_match.teacher_id OR sent_match.teacher_id IS NULL) AND (school_jobs.school_jobs_id != sent_match.job_id OR sent_match.job_id IS NULL)