Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2009
    Posts
    16

    Unanswered: Many-to-Many Query Help

    I have a classical many-to-many DB design: Contractors_table, Trades_table, Contract_Trades.

    I am looking to run a query that will return what trades this contractor does not do.

    Any help will be greatly appreciated.

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    "trades this contractor does not do" --
    Code:
    SELECT t.id
         , t.name
      FROM Trades_table AS t
    LEFT OUTER
      JOIN Contract_Trades AS ct
        ON ct.trade_id = t.id
       AND ct.contractor_id = 937
     WHERE ct.contractor_id IS NULL
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Dec 2008
    Posts
    135
    hi socca,
    if u have small data then try with not in r not exists also queries
    according to performance exists will have more performance than in
    i think so............

  4. #4
    Join Date
    Jan 2009
    Posts
    16
    Thank you r937 that worked perfectly.

Posting Permissions

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