代码之家  ›  专栏  ›  技术社区  ›  Ben

Query IN()未按预期工作

  •  0
  • Ben  · 技术社区  · 14 年前

    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 回复  |  直到 14 年前
        1
  •  3
  •   iamtheexp01    14 年前

    如果“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
    
        2
  •  1
  •   theazureshadow    14 年前

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