I have a cities table which looks like this.
|id| Name |
|1 | Paris |
|2 | London |
|3 | New York|
I have a tags table which looks li
Could this be a push in the right direction?
SELECT cities.name, (
SELECT cities.id FROM cities
JOIN cities_tags ON cities.id=cities_tags.city_id
WHERE tags.id IN(
SELECT cities_tags.tag_id
FROM cites_tags
WHERE cities_tags.city_id=cites.id
)
GROUP BY cities.id
HAVING count(*) > 0
) as matchCount
FROM cities
HAVING matchCount >0
What I tried was this:
// Find the citynames:
Get city.names (SUBQUERY) as matchCount FROM cities WHERE matchCount >0
// the subquery:
select the amount of tags cities have which (SUBSUBQUERY) also has
// the subsubquery
select the id of the tags the original name has