I started to use OpenGeoDB to find the zip code and the city name. My MySQL query reads like this:
SELECT `d`.`text_val` AS `city`, (
SELECT `text_val`
FROM `geodb_textdata`
WHERE `loc_id` = ANY (
SELECT `loc_id`
FROM `geodb_textdata`
WHERE `text_val` LIKE '08%'
)
AND `text_type` = '500300000'
) AS `plz`, `c`.`lat`, `c`.`lon`
FROM `geodb_textdata` AS `d`
LEFT JOIN `geodb_coordinates` AS `c` USING (`loc_id`)
WHERE `loc_id` = ANY (
SELECT `loc_id`
FROM `geodb_textdata`
WHERE `text_val` LIKE '08%'
)
AND `text_type` = '500100000'
If I run this query with a full zip code or city name it works great, but with the code above, I get the error code
#1242 - Subquery returns more than 1 row
I was using Google and I found, that I should use ANY between the = and the subquery. Do you have any idea how I could fix my code? Thank you in advance. 🙂
I suspect that this subquery is returning more than 1 row:
Update: Untested, but give this query a try.