dongliyi967823 2015-08-07 22:04
浏览 33
已采纳

如何检查列值是否在字符串SQL中

I have a database with 150,000 records and I need to match its FULL column value or records, with some parts of the string. **

As i want to check if the STRING contains the COLUMN records and NOT! if the COLUMN contains the string

** (Example below)

For testing purposes Lets say the database has a TABLE , 1 COLUMN and 1 record as the records are similar to this:

  • come to me

and i need to match it with this @STRING

  • She wants to come to me now

I want to execute something similar to :(but this doesn't work of course)

SELECT * from TABLE where @STRING like '%'+COLUMN+'%'

I can't seem to solve this with SQL the usage of PHP is possible but prefer if the solution is with SQL but if the solution with PHP is available please propose it and note that the database has over 150,000 records

  • 写回答

2条回答 默认 最新

  • douyou9923 2015-08-07 22:10
    关注
    SELECT * from TABLE where LOCATE(COLUMN, @STRING)>0;
    

    LOCATE(a,b) returns a number giving the character location of a in b, or returns 0.

    See Mysql LOCATE()

    The docs discuss that LOCATE() is only case sensitive when one of the strings is a 'binary string'. That probably doesn't affect your use case, though if it became an issue you could CONVERT() the binary strings to a locale and use LOWER() to get lower case.

    MySQL String Functions

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的