Results 1 to 3 of 3

Thread: Query Help

  1. #1
    Join Date
    Sep 2002
    Location
    Toronto, Canada
    Posts
    76

    Unanswered: Query Help

    I'm interested in finding the minimim A.id such that the following holds:

    select A.charge
    , B.user_id
    , C.employee_id
    from A
    inner join B using (user_id)
    inner join C using (employee_id)

    except

    select X.charge
    , Y.user_id
    , Z.employee_id
    from X
    inner join Y using (user_id)
    inner join Z using (employee_id)

    --

    A better description of the query:

    select min(A.id) such that A.charge, B.userid, C.employee_id in
    (
    select A.charge
    , B.user_id
    , C.employee_id
    from A
    inner join B using (user_id)
    inner join C using (employee_id)

    except

    select X.charge
    , Y.user_id
    , Z.employee_id
    from X
    inner join Y using (user_id)
    inner join Z using (employee_id)
    )

    Can someone help me with the query? I have no idea how to write it.

    Thanks in advance.

  2. #2
    Join Date
    Apr 2003
    Location
    NY
    Posts
    208

    Re: Query Help

    This assumes that table A and X have Charge, User_id, and Employee_Id as columns.

    PHP Code:
    Select min(A.id)
    From A inner join B on a.user_id b.user_id
               inner join C on a
    .employee_id c.employee_id
    Where not Exists 
    (
       
    Select 'N'
       
    From X inner join Y on x.user_id y.user_id
                  inner join Z on x
    .employee_id z.employee_id
       Where x
    .charge a.charge
           
    and y.user_id b.user_id
           
    and z.employee_id c.employee_id

  3. #3
    Join Date
    Sep 2002
    Location
    Toronto, Canada
    Posts
    76
    Thanks alot carloa, I've been looking for help on the query for months now. I didn't even think about using the not exist clause.

Posting Permissions

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