I’m probably missing something, but I can’t make a simple SQL query work.
I have 2 tables City and Event and I want to see all cities that hosted any event.
The code below seems to perform something odd, because it just overloads PHPMyAdmin.
SELECT city.name, city.date, city.gh, city.ga
FROM city
LEFT JOIN event ON city.id = event.city
When I tried natural join, it displayed all events that were hosted in any city as expected.
You need to change two things:
INNERjoin (don’t use theLEFTkeyword)DISTINCTkeyword, otherwise you’ll get the same city returned many times (once for each event it hosted)Try this:
You could also accomplish this using a sub-select, like this:
Personally, I find the sub-select easier to understand – it’s almost like the English you used to describe the problem.