Paul B. Paul B. - 8 days ago 5x
MySQL Question

How to search for a shared column value between two rows?

I am using Node.js with the mysql module and trying to figure out how I can search for all instances in a table where two users share a similar tag. A quick demo of my table would be:

username | tag
jennifer | coffee
jennifer | pizza
jennifer | travel
joe | sushi
joe | bowling
joe | coffee
joe | travel
celine | singing
celine | pizza
celine | programming

So for example I would like to find what the tags are that joe and jennifer have in common which in this case would be two: coffee and travel. What is the best way to search for the tags they have in common? Any advice would be helpful. Thank you in advance!


this will find common tags providing 2 names:

FROM yourTable
WHERE username in ("jennifer", "joe")
HAVING count(*) > 1