Need help with a patter match query

Discussion in 'Databases' started by Lost&found, May 27, 2010.

  1. #1
    OK so lets say you have a table with 6 columns and you want to query with a pattern match on 4 columns. How do I do this?

    I can produce accurate result with 1 column like this:

    SELECT * FROM tableName WHERE name LIKE '%pattern%'

    That works with one column like 'name' but if I wanted to query other columns like name,title,comment,ect how would I form this SQL statement?

    details:

    MySQL 5.0.77
    Al cols are Latin_general_ci

    Ya I am a newbie with this stuff.....:(
     
    Lost&found, May 27, 2010 IP
  2. miker81

    miker81 Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    SELECT * FROM country WHERE (name LIKE '%p1%') and (rus_name LIKE '%p2%')
     
    miker81, May 28, 2010 IP
  3. Lost&found

    Lost&found Guest

    Messages:
    13
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I am assuming "rus_name" is the next column I am calling on to query?

    SELECT * FROM table_name WHERE (name LIKE '%you%') AND (title LIKE '%me%') AND (comment LIKE '%el%')

    Thanks for the reply!
     
    Lost&found, May 28, 2010 IP
  4. Lost&found

    Lost&found Guest

    Messages:
    13
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Although this is valid syntax this query using the above format return zero results when it should return 3 user names with 'guy' in their user names.

    query: SELECT * FROM kwaks WHERE (name LIKE '%guy%') AND (title LIKE '%guy%') AND (comment LIKE '%guy%')

    Suggestions anyone?
     
    Lost&found, May 28, 2010 IP
  5. miker81

    miker81 Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Try OR instead of AND,
    SELECT * FROM kwaks WHERE (name LIKE '%guy%') OR (title LIKE '%guy%')
    Or maybe i misunderstood you question ?
     
    miker81, May 29, 2010 IP
  6. Lost&found

    Lost&found Guest

    Messages:
    13
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
     
    Lost&found, May 29, 2010 IP
  7. iimmdeepak

    iimmdeepak Peon

    Messages:
    208
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #7
    but with it u will check for any from all and if i have to check patter in all 3 column then and query is correct.

    select * from emp where (ename like 'S%') and (job like 'C%');
    u will get i column output
     
    iimmdeepak, Jun 10, 2010 IP