Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2013

    Unanswered: Select Statement With Table Constraints

    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 | prim_parent_id | sec_parent_id

    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 is the statement thus far: 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'))

    I have the statement working for the above criteria but now i need to also select the rows that match the prim_parent_id and sec_parent_id from the above results.

  2. #2
    Join Date
    Feb 2004
    In front of the computer
    Provided Answers: 54
    What is your question?

    I'd approach the syntax differently, but what you've got appears to be syntactically correct.

    In theory, theory and practice are identical. In practice, theory and practice are unrelated.

  3. #3
    Join Date
    Nov 2013
    How could I select the rows in the same table that correspond with the prim_parent_id and sec_parent_id from the results of the provided statement?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts