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条)

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!