basic SELECT question

Discussion in 'PHP' started by fgs, May 23, 2007.

  1. #1
    Scenario:
    I am trying to select all entries where 'title' field starts with a letter that comes in the alphabet before 'M'.

    would it be as simple as

    select * from stuff where title < M;
    PHP:
    or how would I go about it?

    Help really appreciated

    Thanks
     
    fgs, May 23, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    
    SELECT * FROM foo WHERE title REGEXP '^[A-L]'
    
    Code (sql):
     
    nico_swd, May 23, 2007 IP
  3. DW1

    DW1 Peon

    Messages:
    111
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Maybe this:
    select * from stuff where upper(substr(title,0,1)) < 'M';
    Code (markup):
    dev.mysql.com/doc/refman/5.0/en/string-functions.html
     
    DW1, May 23, 2007 IP
  4. lemaitre

    lemaitre Peon

    Messages:
    61
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Your first instinct was good, you just needed to quote it:

    select * from stuff where title < 'M'
    Code (markup):
    Works fine for me. Or to get authors starting with the letter "S":

    select * from author where author >= 'S' and author < 'T';
    Code (markup):
     
    lemaitre, May 23, 2007 IP
  5. fgs

    fgs Peon

    Messages:
    967
    Likes Received:
    22
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Thank you very much for help guys, DP rocks
     
    fgs, May 23, 2007 IP