View Single Post

  #2 (permalink)  
Old 05-06-2008
Warren
 
Posts: n/a
Default Re: Eliminating Multiple Rows

The query is actually:

SELECT sw.*, i.*
FROM `SOFTWARE` sw
LEFT OUTER JOIN `INSTALLS` i ON i.`software` = sw.`id`
WHERE i.`system` IS NULL OR (NOT i.`system` = {id}) ;

Warren wrote:
> I've been trying to think of how to complete this with a single query,
> but my knowledge of exactly which function would be useful here is
> limited.
>
> The situation:
> I have an indexed table that refers to two other tables, call it
> 'INSTALLS'. INSTALLS contains two indexed columns, SYSTEM and
> SOFTWARE, which point to their respective tables.
>
> What I want to do, is for a given SYSTEM ID, return all SOFTWARE IDs
> which are *not* listed in INSTALLS.
>
> The query so far:
> SELECT sw.*, i.*
> FROM `SOFTWARE` sw
> LEFT OUTER JOIN `INSTALLS` i ON i.`software` = sw.`id`
> OR i.`system` IS NULL OR (NOT i.`system` = {id}) ;
>
> The problem with this is that if the software is listed as installed
> on another system, it will always be returned, even if it is already
> installed on the system with ID {id}.
>
> I'm sorry if this is a bit confusing, it's hard to wrap my head
> around, but I'll try to clarify if needed.

Reply With Quote