List:General Discussion« Previous MessageNext Message »
From:Jouni Hartikainen Date:October 15 2003 10:41am
Subject:Re: How to search by groups efficiently with MySql 4.0.15?
View as plain text  
Hi

>A group_id cannot be both 1 AND 3, but it can be  1 OR 3.
>Try OR

Yes. I know that group_id can't be both 1 and 3 at the same time. This is 
exactly
my problem. How to find a record that belongs to both groups 1 AND 3?
If I use OR here, I get also records that only belong to group 1 or only
belong to group 3. But I don't want these records.

For example:

I have three records A, B and C. A belongs to groups 1 and 2, B belongs to 
group
1 and C belongs to group 2. Now I wan't to find a record that belongs to 
groups
1 AND 2. (So I want that the result for my query is only group A) How can I 
do that?
Not with OR I think.

Any ideas? Or do I just have to take everything out from DB and then 
manually
loop through all records in my client code?


Sincerely,

Jouni Hartikainen
kalle_kukkanen@stripped


>Jouni Hartikainen wrote:
>
>>
>>Hi.
>>
>>> > how about:
>>> >
>>> > select record.*
>>> > from link
>>> > where group_id='x'
>>> > left join record on record.archive_id=link.archive_id
>>> > ?
>>
>>
>>The problem with this query is that with simple left join, I can search 
>>only by a single group.
>>If I set x to 3 here, I get all records that belong to group 3. But what 
>>about if I want to have all records that belong to groups 1 AND 3? If I 
>>add condition "WHERE group_id='1' AND group_id='3'", I get no results at 
>>all, since left join doesn't produce such rows that have multiple group_id 
>>columns.
>>
>>
>>Sincerely,
>>
>>Jouni Hartikainen
>>kalle_kukkanen@stripped

_________________________________________________________________
MSN 8 with e-mail virus protection service: 2 months FREE* 
http://join.msn.com/?page=features/virus

Thread
How to search by groups efficiently with MySql 4.0.15?Jouni Hartikainen11 Oct
RE: How to search by groups efficiently with MySql 4.0.15?Pakó Géza11 Oct
RE: How to search by groups efficiently with MySql 4.0.15?Jouni Hartikainen12 Oct
  • Re: How to search by groups efficiently with MySql 4.0.15?gerald_clark13 Oct
Re: How to search by groups efficiently with MySql 4.0.15?Jouni Hartikainen15 Oct
  • Re: How to search by groups efficiently with MySql 4.0.15?Roger Baklund15 Oct
Re: How to search by groups efficiently with MySql 4.0.15?Jouni Hartikainen16 Oct