这个SQL语句有问题吗? 具体来说,在“LIKE?AND deck_id =?”中一部分。
"SELECT * FROM cards WHERE
card_one LIKE ? OR card_two LIKE ? OR card_three LIKE ?
AND deck_id = ? OR deck_id = ? OR deck_id = ? OR deck_id = ?
OR deck_id = ? OR deck_id = ? OR deck_id = ?"
它正确搜索card_one和card_two,但不是第三个。如果我把card_three拿出来,那么card_two不起作用。这让我相信那个领域的事情是不对的。
你能用这种方式使用LIKE吗?
期望的结果
"SELECT * FROM cards WHERE (card1-3 LIKE ?) AND (Deck_id = decks_array)"
如果这是有道理的。
答案 0 :(得分:3)
"SELECT * FROM cards WHERE
(card_one LIKE ? OR card_two LIKE ? OR card_three LIKE ?)
AND deck_id in (id1,id2,id3)
答案 1 :(得分:2)
您需要在条件周围添加(...)
,如下所示:
"SELECT * FROM cards WHERE
( card_one LIKE ? OR card_two LIKE ? OR card_three LIKE ? )
AND ( deck_id = ? OR deck_id = ? OR deck_id = ? OR deck_id = ?
OR deck_id = ? OR deck_id = ? OR deck_id = ? )"