I am trying to select with some specific conditions but cannot seem to get what I am wanting.
Table Person person_id | first_name | last_name
Table Service service_id | person_id | start_time | end_time | service_type_id
Table Service_Types type_id | description
Table Service_User service_id | start_time | end_Time | user_id
The goal is to get all of the person_id's that meet any of the following criteria:
- Last Name Like 'Mar%'
- Service Type Like 'Fusions%'
- Service Type Like 'New%' And User_Id = 'Bob' And Start_Time On Or After 2009-01-01
Here's the statement I have been trying to use:
SELECT DISTINCT person_id FROM person P,service S, service_types ST, service_user SU WHERE P.person_id = S.person_id AND S.service_id = SU.service_id AND ST.type_id = S.service_type_id AND (P.last_name LIKE 'Mar%' OR ST.description LIKE 'Fusions%') OR (ST.description LIKE 'New%' AND SU.user_id = 'Bob' AND start_time >= '2009-01-01')
See Question&Answers more detail:os