开发者

Returning Multiple Entries With WHERE subseach

I'm facing the following problem: I have a table (new_form) that lists units that should answer a formulary. The information about those units are in another table (units), including the code of city (city_code) where they are. I want to find the information in the first table (new_form) about all the units that are there and are located in an specific city (8383).

SELECT * FROM `new_form`
WHERE `unit_number`=(
    SELEC开发者_StackOverflow中文版T `unit_number`
    FROM `units`
    WHERE `city_code`=8383
)

The way it is now, I get this error:

#1242 - Subconsulta retorna mais que 1 registro


Use IN:

SELECT * 
FROM `new_form`
WHERE `unit_number` in (
    SELECT `unit_number`
    FROM `units`
    WHERE `city_code`=8383
)

Alternately, you could use a JOIN:

SELECT f.* 
FROM `new_form` f
INNER JOIN `units` u on f.`unit_number` = u.`unit_number`
WHERE u.`city_code`=8383
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜