Php SQL:如何在数据字段中选择带有逗号的数据?

Php SQL:如何在数据字段中选择带有逗号的数据?,php,mysql,sql,sql-server,Php,Mysql,Sql,Sql Server,表A: id book_title ----------------- 1 Harry,Potter 2 Limitless 案例1: select * from A where book_title like '%Harry%' Output: 1 Harry,Potter 它起作用了 但在案例2中: select * from A where book_title like '%HarryPotter%' Output: <Nothing> 谢谢。只需在wh

A

id  book_title 
-----------------
1   Harry,Potter
2   Limitless
案例1:

select * from A where book_title like '%Harry%'

Output:
1 Harry,Potter
它起作用了

但在案例2中:

select * from A where book_title like '%HarryPotter%'

Output:
<Nothing>

谢谢。

只需在where语句中插入逗号,或者如果您不确定这两个词之间是什么,请使用%即可:

select * from A where book_title like '%Harry%Portter%'

只需在where语句中插入逗号或使用%即可。如果您不确定这两个单词之间的位置:

select * from A where book_title like '%Harry%Portter%'
在这种情况下,您需要函数

SELECT ... WHERE FIND_IN_SET('Harry', field)
在这种情况下,您需要函数

SELECT ... WHERE FIND_IN_SET('Harry', field)

执行类似于的
操作时,首先使用
替换
从书名中删除任何

select * from A where replace(book_title,',','') like '%HarryPortter%'

执行类似于
操作时,首先使用
替换
从书名中删除任何

select * from A where replace(book_title,',','') like '%HarryPortter%'

当参数可以改变时,它工作。不管怎样,谢谢。当参数可以更改时,它工作。无论如何,谢谢。