SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    Bah, I'll just hack it DoobyWho's Avatar
    Join Date
    Jul 2002
    Posts
    476
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    MySQL 'LIKE' syntax

    How would i do multiple LIKE clauses?

    Here's the statement:

    "SELECT FROM Catalog WHERE product LIKE '%$prodSEARCH%' AND sku LIKE '%$skuSEARCH%'";

    That's not correct...

  2. #2
    SitePoint Zealot zbing's Avatar
    Join Date
    Jun 2002
    Location
    Lisbon, Portugal
    Posts
    159
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What do you mean by:
    That's not correct...
    ???
    zbing

  3. #3
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,216
    Mentioned
    58 Post(s)
    Tagged
    3 Thread(s)
    i don't do php, but don't you have to concatenate the literals and variables together somehow?

    "SELECT FROM Catalog
    WHERE product LIKE '%" + $prodSEARCH + "%'"
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  4. #4
    SitePoint Zealot zbing's Avatar
    Join Date
    Jun 2002
    Location
    Lisbon, Portugal
    Posts
    159
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't know what you mean but here goes my guess:


    PHP Code:
    //One thing: You say (SELECT FROM Catalog...)! SELECT WHAT?!
    //But anyway try this...

    SELECT product FROM Catalog WHERE product LIKE '%$prodSEARCH%' 
    UNION 
    SELECT product FROM Catalog sku LIKE 
    '%$skuSEARCH%'"; 
    UNION is only available in MySQL 4 i think.

    Its much like doing 2 separate queries but it outputs the results into a single set...

    Hope this is what you needed...
    zbing

  5. #5
    Your Lord and Master, Foamy gold trophy Hierophant's Avatar
    Join Date
    Aug 1999
    Location
    Lancaster, Ca. USA
    Posts
    12,305
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    The original query works just fine for me. No need to change it.

    I tested this in MySQL 3.23.49a.
    Wayne Luke
    ------------


  6. #6
    SitePoint Zealot zbing's Avatar
    Join Date
    Jun 2002
    Location
    Lisbon, Portugal
    Posts
    159
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Isn't it necessary to specify whan you're looking for in the SELECT query? E.G. [SELECT * / SELECT potatoes] or by omiting it MySQL will adopt the same behaviour as with SELECT * ?
    zbing

  7. #7
    Your Lord and Master, Foamy gold trophy Hierophant's Avatar
    Join Date
    Aug 1999
    Location
    Lancaster, Ca. USA
    Posts
    12,305
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Oh I guess I instinctively put in the * when I did it.

    For all intents and purposes, I tested the syntax not the query because I don't have a database that matches that.

    Anyway, here is the exact query I used (on this forum's database)...

    Code:
    SELECT * FROM forum WHERE title LIKE '%HTML%' AND description LIKE '%HTML%'
    Wayne Luke
    ------------



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
  •