SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Zealot y2kbug's Avatar
    Join Date
    Nov 2004
    Location
    Hong Kong
    Posts
    173
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to find keywords in MySQL?

    We can found a row of data with an exact word, like:
    select * from table where word = 'abc';

    But, how to search a row of data with an entered keyword?
    select * from table where keyword ........ 'abc';
    ???

    Thanks~

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,347
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    you must search all the columns individually, there is no way to search a "row"
    Code:
    select title
         , comments
         , description
      from daTable
     where title like '%keyword%'
        or comments like '%keyword%'
        or description like '%keyword%'
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Zealot y2kbug's Avatar
    Join Date
    Nov 2004
    Location
    Hong Kong
    Posts
    173
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by r937
    you must search all the columns individually, there is no way to search a "row"
    Code:
    select title
         , comments
         , description
      from daTable
     where title like '%keyword%'
        or comments like '%keyword%'
        or description like '%keyword%'
    and, how should the data (keyword) be stored?
    comma separated?

  4. #4
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,347
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    no, typically you don't store the keywords at all

    what are you trying to do?
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  5. #5
    SitePoint Zealot y2kbug's Avatar
    Join Date
    Nov 2004
    Location
    Hong Kong
    Posts
    173
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by r937
    no, typically you don't store the keywords at all

    what are you trying to do?
    for example, when a person register, he/she has to enter his/her hobby.
    Now, i want to find out those people with hobby "sleeping".
    How to do this?
    I have tried "Select * from table where hobby like "sleeping", that it isn't work.

  6. #6
    SitePoint Zealot y2kbug's Avatar
    Join Date
    Nov 2004
    Location
    Hong Kong
    Posts
    173
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by r937
    you must search all the columns individually, there is no way to search a "row"
    Code:
    select title
         , comments
         , description
      from daTable
     where title like '%keyword%'
        or comments like '%keyword%'
        or description like '%keyword%'
    got it!
    Thanks~
    =3=


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •