I have two tables
Table name: place
Columns: placeid, name
Data: 1, My Favourite Donut Place
Table name: category
Columns: categoryid, name, placeid
Data: 1, Donuts, 1
2, Coffee, 1
3, Hot Chocolate, 1
I join the two like this:
select p.name as place, c.name as category from place p join category c on p.placeid=c.placeid
And would get a result like this:
place category
My favourite donut place Donuts
My favourite donut place Coffee
My favourite donut place Hot Chocolate
Now I want to search for places that serve coffee:
select p.name as place, c.name as category from place p join category c on p.placeid=c.placeid where c.name = 'Coffee'
Result like this:
place category
My favourite donut place Coffee
But I still want to show all the different categories for "My favourite donut place" that serves coffee, i.e. "Donuts" and "Hot Chocolate" too.
What would be the best way to go about to accomplish that?