MySQL Forums
Forum List  »  General

Searching on a field from multiple rows matching a groupId
Posted by: Jerry Malcolm
Date: May 20, 2019 09:36PM

I have a table where several rows have the same value in a 'groupId' col. I need to select the groupId if "abc" is found in colX in any row in a specific 'group' of rows AND "xyz" is also found in colX in any row in the same group rows (doesn't have to be the same row). In other words, both abc and xyz have to exist somewhere in colX in rows with the same groupId. I've been coding SQL for many years. But this one has me stumped. I think it may have something to do with grouping and concat. But I'm at a standstill.

1 1 aaa bbb abc ccc
2 1 ddd eee fff
3 1 ggg xyz
4 2 abc hhh iii
5 2 jjj kkk
6 2 lll mmm

The query should return groupid 1 since abc is found in ndx 1 and xyz is found in ndx 3, both a part of groupid 1. It should not return groupid 2 since even though abc is found in ndx 4, no record with groupid 2 contains xyz.

Can someone help me out with the magical MySQL incantation to query this?

Thanks in advance.


Options: ReplyQuote

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.