MySQL Forums
Forum List  »  General

Help Formulating Complex LEFT JOIN Query
Posted by: Jonathan Shaltz
Date: September 30, 2005 10:46AM

Good mornig, everyone. I hope someone can help me formulate a query; I know how it needs to work but I don't know exactly how to phrase it. This is the closest I've come:

SELECT * FROM Trades LEFT JOIN (Trades AS Trades2 NATURAL JOIN Vendors WHERE Vendors.Company = X) ON Trades.Trade = Vendors.Trade WHERE Vendors.Company IS NULL;

Trades is a list of trades, Vendors relates Trades to Companies on a many-many basis. What I'm trying to do is get a list of all Trades that DON'T exist in Vendors for a specific company. That is, what Trades does Company X NOT do?

This is the diagram I made to try to figure out how to make it work:

Trades = {A, B, C}
Vendors = {A} WHERE Company = X
Goal = {B, C} (all Trades EXCEPT those in Vendors for Company X

Thank you!

Options: ReplyQuote

Written By
Help Formulating Complex LEFT JOIN Query
September 30, 2005 10:46AM

Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.