MySQL Forums
Forum List  »  German

Re: Schnittmenge in WHERE-clause?
Posted by: Daniel Jonas
Date: January 27, 2009 05:00PM

ein Kollege hats geknackt:

SELECT id FROM t1
WHERE '1,4,8' = (
SELECT group_concat( id_t2 SEPARATOR ',' ) AS gr
FROM tmn
WHERE t1.id = id_t1 AND id_t2 IN ( 1, 4, 8 )
GROUP BY id_t1
)

da ich m = (1,4,8) ja vor dem SELECT kenne, kann man auch ueber den Count nen bissl optimieren:

SELECT id FROM t1
WHERE 3 = (
SELECT count( id_t2 ) AS gr
FROM tmn
WHERE t1.id = id_t1 AND id_t2 IN ( 1, 4, 8 )
GROUP BY id_t1
)

ich denke besser gehts nicht, oder?

gruss, dj

Options: ReplyQuote


Subject
Views
Written By
Posted
7932
January 10, 2009 03:03PM
4127
January 10, 2009 05:21PM
2842
January 14, 2009 08:26AM
Re: Schnittmenge in WHERE-clause?
3076
January 27, 2009 05:00PM


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.