SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Evangelist
    Join Date
    Jun 2004
    Posts
    417
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to find rows where SUBSTRING is...

    Hello,

    can anyone help me please ?

    I want to extraxt all rows from a table where some column starts with some given letter. For exampple : Give me all brands from the table brands where the first letter of the brand is an 'a' ?

    Many thanks,
    Michel

  2. #2
    SitePoint Guru MikeBigg's Avatar
    Join Date
    Jun 2004
    Location
    Reading, UK
    Posts
    970
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This might help:

    select * from brands where brandname like 'a%'

    The % character is a widcard

    Mike

  3. #3
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,350
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    you can also do this --

    ... where left(brand,1) = 'a'
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  4. #4
    SitePoint Addict trogdor1024's Avatar
    Join Date
    Oct 2004
    Location
    New Jersey
    Posts
    235
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you might want to throw in a LOWER() as well in case you are looking for an "a" or "A". (It might not matter but I believe it is case sensitive).

    ... where left(LOWER(brand),1) = 'a'

  5. #5
    SitePoint Evangelist
    Join Date
    Jun 2004
    Posts
    417
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's working :-)
    Thank you very much.

    Michel


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
  •