Selecting rows based on their key existing in another table.

Posts   
 
    
BexMed
User
Posts: 63
Joined: 18-Jul-2007
# Posted on: 17-Mar-2008 18:22:24   

Hello

I have two tables Group and GroupItem, where a Group contains GroupItems. I want to select all group names which contain items, ie not show any groups where their id does not exist in the group item table.

I know this sounds really simple, but for some reason I am really struggling.

Can you help?

Thanks

Bex

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 18-Mar-2008 06:15:31   

You could use the FieldCompareSetPredicate, should look like:

RelationPredicateBucket bucket = new RelationPredicateBucket();
bucket.PredicateExpression.AddWithAnd(new FieldCompareSetPredicate(GroupFields.GroupId,
                    GroupItemFields.GroupId, SetOperator.In, (GroupFields.GroupId == GroupItemFields.GroupId), false));

Find at the Docs or Forums for FieldCompareSetPredicate for more info wink

David Elizondo | LLBLGen Support Team