I Think I do not understand something but i have a very strange result with not in.
I have this kind of tables
TABLE membres
idMembre
1
2
...
Table membres_has_domaines
idMembre idDomaine
1 10
1 11
1 40
2 10
2 13
2 20
3 40
3 22
i run this query
select m.idMembre from membres m
inner join membres_has_domaines md on m.idMembre=md.idMembre
where md.idDomaine not in (40)
group by m.idMembre
and the result retuns me
idMembre
1
2
3
the question is... why user 1 and 3 is in this result ?
thanks a lot for your help
EDIT : after first answer, i understand the problem... in reality my request is many more complex. I'm working on a full dynamic filter system generated by a HTML form where you choose your parameters... requests looks like that. here i want members with domain matching (1,2) excluding members with domain 27 and having country in (64, 4, 24)
select m.idMembre, memberName,
GROUP_CONCAT(distinct d.domaineName SEPARATOR ", ") as domaines ,
GROUP_CONCAT(distinct a.zipAdresse SEPARATOR ", ") as zips,
GROUP_CONCAT(distinct p.countryName SEPARATOR ", ") as countryNames
from membres
m left join titres t on m.idTitre=t.idTitre
left join civilites c on m.idCivilite=c.idCivilite
left join adresses a on a.idMembre=m.idMembre left
join pays p on a.idCountry =p.idCountry
left join emails e on e.idMembre=m.idMembre
left join membres_has_domaines md on md.idMembre=m.idMembre
left join domaines d on md.idDomaine=d.idDomaine
where 1=1 and md.idDomaine in (1, 2)
and md.idDomaine not like '27'
and a.idCountry in (64, 4, 24)
group by m.idMembre
note ... this query don't do the job .. for the same reason of my original simplified example.
i don't know if i can do that without using having clause or subqueries ... it's quite complex. I think, the subqueries are the only way ? what do you think ? ...