MySQL SELECT query string matching

后端 未结 3 1161
佛祖请我去吃肉
佛祖请我去吃肉 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 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)

提交回复
热议问题