查询IN()无法按预期工作

时间:2010-11-12 02:23:38

标签: mysql

如果我运行查询:

SELECT board.id, board.name
FROM board
INNER JOIN group_assoc ON group_id
IN (
"4,9,12,15,18,21,22,55,57,83,84,86,89,92,95,98,104,105"
)
AND group_assoc.board_id = board.id
INNER JOIN category ON category.id = board.category_id
AND category.forum_id =2

我得到的结果与

不同
SELECT board.id, board.name
FROM board
INNER JOIN group_assoc ON group_id = 9
AND group_assoc.board_id = board.id
INNER JOIN category ON category.id = board.category_id
AND category.forum_id =2

它只是拉板可以被所有组看到吗?

2 个答案:

答案 0 :(得分:3)

如果“IN”中的值是整数,请不要使用双引号(“”),如下所示


SELECT board.id, board.name
FROM board
INNER JOIN group_assoc ON group_id
IN (
4,9,12,15,18,21,22,55,57,83,84,86,89,92,95,98,104,105
)
AND group_assoc.board_id = board.id
INNER JOIN category ON category.id = board.category_id
AND category.forum_id =2

如果值是字符串,请为每个字符串使用双引号。


SELECT board.id, board.name
FROM board
INNER JOIN group_assoc ON group_id
IN (
"4121213","9434345443","12545454"
)
AND group_assoc.board_id = board.id
INNER JOIN category ON category.id = board.category_id
AND category.forum_id =2

答案 1 :(得分:1)

尝试IN (4,9,12,...)