Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2002
    Posts
    3

    Unanswered: Need help with a 3 table query

    Hi all,

    I need some help with a query:
    I have 3 tables:

    tbl_trainer_bookings
    .trainer_booking_id PK
    .slot_id
    .trainer_id

    tbl_slots
    .slot_id PK

    temp1 (temporary table, trainer_id could be considered PK)
    .trainer_id

    I need a list of all combinations of
    trainer_id and slot_id that are not in
    tbl_trainer_bookings.

    Hope this is a clear enough explanation,
    and that somebody will be able to help me!

    Regards,

    Ballonier

  2. #2
    Join Date
    Sep 2002
    Posts
    30

    Re: Need help with a 3 table query

    try this

    select slot_id, trainer_id from tbl_slots, temp1 where
    slot_id not in (select slot_id from tbl_trainer_bookings)
    and trainer_id not in (select trainer_id from tbl_trainer_bookings)

  3. #3
    Join Date
    Oct 2002
    Posts
    3
    Thanks for the reply.

    Your query will not give any possible combination, it will exclude
    all trainer_id's and slot_id's that are in tbl_trainer_bookings.

    Anyway, I found out by now, so here's the complete query:

    SELECT temp1.trainer_id,
    tbl_slots.slot_id
    FROM tbl_slots
    CROSS JOIN temp1
    LEFT OUTER JOIN tbl_trainer_bookings
    ON tbl_trainer_bookings.trainer_id = temp1.trainer_id
    AND tbl_trainer_bookings.slot_id = tbl_slots.slot_id
    WHERE tbl_trainer_bookings.trainer_id IS NULL
    Last edited by Ballonier; 10-29-02 at 09:59.

Posting Permissions

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