List:General Discussion« Previous MessageNext Message »
From:Benjamin Pflugmann Date:March 8 2000 3:30am
Subject:Re: tricky SQL needs expert...
View as plain text  
Hi.

Did not test it, but something like the following would probably do
the job:

SELECT   p.elementNAME,
         SUM( IF( (e.elementID IN (A,B,C)), 0, 1 ) ) AS wrong_hits
FROM     element p, element e
WHERE    p.packageID = '0' AND 
         e.packageID = p.elementID
GROUP BY p.elementID
HAVING   wrong_hits = 0

If you have a lot of 'wrong_hits', this may get significantly slower.

Bye,

        Benjamin.
        

On Fri, Mar 03, 2000 at 03:05:00PM -0800, ted@stripped wrote:
> Ok, I've basically got an answer. With regards to the second
> question: I first query the database for all packages with
> elements not in the set (in this example, everything not in
> A, B, C). Then I query the database again for all packages
> containing any of the elements in the set BUT where the 
> packages are not in the set of packages returned in the
> first query. For the first question: The SQL is as follows
> (provided by Nicholas Prade)
> 	Hello.
> 	Supposing
> 	- elementID is unique
> 	- your table name is: element
> 	- A,B and C are the 3 element's IDs
> 	You can try:
> 
> 	SELECT p.elementNAME, COUNT(e.elementID) AS nb
> 	FROM element p, element e
> 	WHERE p.packageID='0' AND e.packageID=p.elementID
> 	AND e.elementID IN (A,B,C)
> 	GROUP BY p.elementID HAVING nb=3
> 
[...]
Thread
tricky SQL needs expert...T.R. Henigson3 Mar
  • RE: tricky SQL needs expert...Nicolas Prade3 Mar
    • RE: tricky SQL needs expert...T.R. Henigson3 Mar
    • RE: tricky SQL needs expert...T.R. Henigson4 Mar
      • Re: tricky SQL needs expert...Benjamin Pflugmann8 Mar