SitePoint Sponsor

User Tag List

Results 1 to 14 of 14

Thread: Difference between LIKE AND like % %

  1. #1
    Level 8 Chinese guy Archbob's Avatar
    Join Date
    Sep 2001
    Location
    Somewhere in this vast universe
    Posts
    3,726
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Difference between LIKE AND like % %

    SO whats the difference between just:
    Code:
    SELECT * from table where field like bob
    And
    Code:
     
    SELECT * from table where field like '%bob%'
    I've always used the second, but whats the difference?

  2. #2
    Prolific Blogger silver trophy Technosailor's Avatar
    Join Date
    Jun 2001
    Location
    Before These Crowded Streets
    Posts
    9,446
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The first matches only bob. The second would match archbob or bobolink or anything with bob in the middle of it. % is a wildcard.
    Aaron Brazell
    Technosailor



  3. #3
    Prolific Blogger silver trophy Technosailor's Avatar
    Join Date
    Jun 2001
    Location
    Before These Crowded Streets
    Posts
    9,446
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Actually I'm wrong. The first doesn't match anything because bob is a string and needs to be enclosed in quotes. In fact, you'll get a MySQL error.
    Aaron Brazell
    Technosailor



  4. #4
    Level 8 Chinese guy Archbob's Avatar
    Join Date
    Sep 2001
    Location
    Somewhere in this vast universe
    Posts
    3,726
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So:
    Code:
    SELECT * from table where field like 'bob'
    Is essentially the same as:
    Code:
    SELECT * from table where field='bob'
    ?

    So is there a select option in string that do like if you have a string like "the bob", search for entries that contain either "the" or "bob"?

  5. #5
    Prolific Blogger silver trophy Technosailor's Avatar
    Join Date
    Jun 2001
    Location
    Before These Crowded Streets
    Posts
    9,446
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes exactly
    Aaron Brazell
    Technosailor



  6. #6
    Level 8 Chinese guy Archbob's Avatar
    Join Date
    Sep 2001
    Location
    Somewhere in this vast universe
    Posts
    3,726
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Archbob


    So is there a select option in string that do like if you have a string like "the bob", search for entries that contain either "the" or "bob"?
    So is there a select state that does this in just mySQL?

  7. #7
    Prolific Blogger silver trophy Technosailor's Avatar
    Join Date
    Jun 2001
    Location
    Before These Crowded Streets
    Posts
    9,446
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    SELECT * FROM table WHERE entry LIKE '%the%' OR LIKE '%bob%';
    Aaron Brazell
    Technosailor



  8. #8
    SQL Consultant silver trophybronze trophy
    SitePoint Award Recipient r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    38,469
    Mentioned
    35 Post(s)
    Tagged
    1 Thread(s)
    WHERE entry LIKE '%the%' OR entry LIKE '%bob%';
    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  9. #9
    Prolific Blogger silver trophy Technosailor's Avatar
    Join Date
    Jun 2001
    Location
    Before These Crowded Streets
    Posts
    9,446
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ah right... thanks r... little overlook there...
    Aaron Brazell
    Technosailor



  10. #10
    Level 8 Chinese guy Archbob's Avatar
    Join Date
    Sep 2001
    Location
    Somewhere in this vast universe
    Posts
    3,726
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, but thats not what I was talking about. I was asking if mySQL had a select that automatically string through a string and split it into individual words by the space.

  11. #11
    SQL Consultant silver trophybronze trophy
    SitePoint Award Recipient r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    38,469
    Mentioned
    35 Post(s)
    Tagged
    1 Thread(s)
    no, there isn't
    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  12. #12
    SitePoint Enthusiast
    Join Date
    May 2004
    Location
    Singapore
    Posts
    37
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Archbob
    Thanks, but thats not what I was talking about. I was asking if mySQL had a select that automatically string through a string and split it into individual words by the space.
    Hi. Sorry dont understand what you mean by auto string through a string and split. Could you explain what you mean ? Cause im also learning SQL and would be glad to find out more
    Singapore Web Hosting Forum - http://www.sgwebhostingtalk.com
    Singapore Soccer - http://www.singaporesoccer.com
    Music Forum and Lyrics - http://www.musicpowered.com
    Dota Allstars Forum - http://www.dota-allstars.info

  13. #13
    SitePoint Guru
    Join Date
    Nov 2004
    Location
    Plano
    Posts
    643
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Archbob
    Thanks, but thats not what I was talking about. I was asking if mySQL had a select that automatically string through a string and split it into individual words by the space.
    you would need the PHP function explode() (or the equivelant in other languages), which puts a string into an array, split by a delimiter.

  14. #14
    Level 8 Chinese guy Archbob's Avatar
    Join Date
    Sep 2001
    Location
    Somewhere in this vast universe
    Posts
    3,726
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm mainly concerned about spaces so split would be good enough here.

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
  •