MySQL SELECT query string matching

后端 未结 3 1157
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-08 02:28

Normally, when querying a database with SELECT, its common to want to find the records that match a given search string.

For example:

SELECT * FROM c         


        
相关标签:
3条回答
  • 2020-12-08 02:56

    Just turn the LIKE around

    SELECT * FROM customers
    WHERE 'Robert Bob Smith III, PhD.' LIKE CONCAT('%',name,'%')
    
    0 讨论(0)
  • 2020-12-08 03:02

    You can use regular expressions like this:

    SELECT * FROM pet WHERE name REGEXP 'Bob|Smith'; 
    
    0 讨论(0)
  • 2020-12-08 03:08

    Incorrect:

    SELECT * FROM customers WHERE name LIKE '%Bob Smith%';
    

    Instead:

    select count(*)
    from rearp.customers c
    where c.name  LIKE '%Bob smith.8%';
    

    select count will just query (totals)

    C will link the db.table to the names row you need this to index

    LIKE should be obvs

    8 will call all references in DB 8 or less (not really needed but i like neatness)

    0 讨论(0)
提交回复
热议问题