How to implement a Keyword Search in MySQL?

后端 未结 7 1081
温柔的废话
温柔的废话 2020-11-29 20:25

I am new to SQL programming.

I have a table job where the fields are id, position, category, location, sala

7条回答
  •  独厮守ぢ
    2020-11-29 20:52

    For a single keyword on VARCHAR fields you can use LIKE:

    SELECT id, category, location
    FROM table
    WHERE
    (
        category LIKE '%keyword%'
        OR location LIKE '%keyword%'
    )
    

    For a description you're usually better adding a full text index and doing a Full-Text Search (MyISAM only):

    SELECT id, description
    FROM table
    WHERE MATCH (description) AGAINST('keyword1 keyword2')
    

提交回复
热议问题