I have 3 tables. An Applications (relevant field is AppID) table containing information about various application available to download, a Packages table (relevant field is PackageID) containg information on the various downloadable items available and an App/Packages table (relevant field is AppID and PackageID) which shows which packages should be downloaded for each application. I need a query to find out which packages are not related to a specific application.
My idea was to INNER JOIN Applications to AppPackages to get a list of all the packages that are related to an Application and then OUTER JOIN this resultant set to Packages and find all the null results to show which packages were not related.
The problem is I can’t seem to work out how to chain these queries. Subqueries don’t seem to work, and EXIST/NOT EXIST requires information from the outer query which I just can’t make work. I’m assuming there’s something simple I’m mising, but all the literature I read is for two tables, never more than two.
This is my best attempt, but the EXISTS part doesn’t work for the reason mentioned above.
SELECT Packages.PackageID FROM Packages WHERE NOT EXISTS
(Select AppPackages.PackageID, AppPackages.AppID FROM AppPackages WHERE AppPackages.AppID = @AppID)
Thanks in advance for any help 🙂
Cheers,
Matt 🙂
1 Answer