MySQL Forums
Forum List  »  MySQL & Kubernetes

Search over mutiple columns having same value in one column
Posted by: Daniel Bäuerlein
Date: September 28, 2022 08:01AM

Hi,

I don't know how to phrase the subject - even more so because my English is not the best.

i have the following question:

Say i have the following datasets in table "persons":

ID sub_id person_a person_b
________________________________________
1 A Daniel 0
2 A 0 Tim
3 B Andrea 0
4 B 0 Stephen
5 C Daniel 0
6 C 0 Tim
7 C Chris 0
8 D Daniel 0

The topic of this article should not be why the database table is structured like this (because I can't change anything) but how I can execute the following query:

Find me all records where Daniel and Tim are entered with the same sub_id, grouped by sub_id.

Result should be: A and C

This has A, C, AND D as result:

SELECT
sub_id
FROM persons
WHERE person_a = Daniel OR person_b = Tim
GROUP BY sub_id


So i think i need something like this

SELECT
sub_id
FROM persons
WHERE person_a = Daniel OR person_b = Tim
GROUP BY sub_id
HAVING THE SAME sub_id

And at this point my sql knowledge is ending ;-(

Can u give me the final tip?

Best regards
Daniel

Options: ReplyQuote


Subject
Written By
Posted
Search over mutiple columns having same value in one column
September 28, 2022 08:01AM


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.