Reputation: 69
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. :)
Upvotes: 2
Views: 241
Reputation: 1777
I suspect that this subquery is returning more than 1 row:
(
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`
Update: Untested, but give this query a try.
SELECT `d`.`text_val` AS `city`, `d2`.`text_val` AS `plz`, `c`.`lat`, `c`.`lon`
FROM `geodb_textdata` AS `d`
LEFT JOIN `geodb_textdata` AS `d2` USING (`loc_id`)
LEFT JOIN `geodb_coordinates` AS `c` USING (`loc_id`)
WHERE `d`.`text_val` LIKE '08%' AND `d`.`text_type` = '500100000'
AND `d2`.`text_val` LIKE '08%' AND `d2`.`text_type` = '500300000'
Upvotes: 2