"LIKE" command of mysql for searching?

Discussion in 'MySQL' started by rahulephp, Apr 21, 2010.

  1. #1
    Hi there,
    Could you please help me to find-out the solution?
    I need to use "LIKE" command of mysql.

    Below are title from a Product table. If i search for "Alarm" then it should show me result only for title which has word alarm. (0th and 2nd only)

    table_name = product
    Column_name = title
    0 ->Casio G-Shock Velocity Indicator Alarm watch
    1 ->Seiko Velatura Tachymeter Chronograph watch
    2 ->Citizen promaster Alarm perpetual watch


    Thank you in anticipation
     
    rahulephp, Apr 21, 2010 IP
  2. cDc

    cDc Peon

    Messages:
    127
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You should do something like

    SELECT title FROM product WHERE title LIKE '%alarm%'

    LIKE queries cause a table scan to find the rows - Once you table gets large, perhaps 10,000 rows you will see low performance and should look at Full Text search...
     
    cDc, Apr 22, 2010 IP
  3. rahulephp

    rahulephp Peon

    Messages:
    45
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Hey thanks
    I got the solution.

    Below command gives all results having keywords Alarm or watch
    SELECT * FROM product where title LIKE '%Alarm%' or '%watch%'
    Code (markup):
     
    rahulephp, Apr 22, 2010 IP
  4. whiteeaglet

    whiteeaglet Peon

    Messages:
    175
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    That's it.
     
    whiteeaglet, Apr 22, 2010 IP
  5. peoplesmind

    peoplesmind Active Member

    Messages:
    107
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    53
    #5
    If you're designing a table, you should initially use FULLTEXT indexes in order to make sure, later on when the table grows large you won't have to go back and do more work to fix the slow queries. Good practice is to optimize initially, and never have to re-code it.
     
    peoplesmind, May 2, 2010 IP
  6. rahulephp

    rahulephp Peon

    Messages:
    45
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Thanks, Will do.
     
    rahulephp, May 5, 2010 IP
  7. bibinsmk

    bibinsmk Active Member

    Messages:
    205
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #7
    How to create FULLTEXT index in mysql?
     
    bibinsmk, May 5, 2010 IP
  8. peoplesmind

    peoplesmind Active Member

    Messages:
    107
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    53
    #8
    CREATE FULLTEXT INDEX name ON column
     
    peoplesmind, May 6, 2010 IP