Results 1 to 6 of 6
  1. #1
    Join Date
    Jul 2004
    Posts
    6

    Unanswered: How to select titles begin with number

    I am trying to find a way to select any record that begins with numbers meaning
    0-infinity.

    I thought using between, but i would have to set the range, but would rather have it just see its a numeral and act accordingly.

    Rich

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    select foo from bar where qux regex '^[0-9]'
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Jul 2004
    Posts
    6
    OK,
    How could i use this with my current select which is selecting anything LIKE $letter%.

    I would like it to Select titles with either numbers or letters but not both.
    Example:

    SELECT * FROM movies WHERE title LIKE $letter% OR title LIKE regex [0-9]

    This isnt the correct code, because I am not sure how to implement.
    Thanks
    Rich

  4. #4
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    Quote Originally Posted by thesandman
    I would like it to Select titles with either numbers or letters but not both.
    could you please give some examples of titles that do not satisfy these criteria (either numbers or letters)
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  5. #5
    Join Date
    Jul 2004
    Posts
    6
    titles that begin with any letter of the alphabet:

    An American Werewolf in London
    The Thing
    Salo

    Any title that begins with numerals like:
    500 Blows
    1,001 ways to kill a cat

    if you go to http://www.rareoopdvds.com/listing.php?letter=e
    you will see what I am actually doing.

    Thanks
    Rich

  6. #6
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    okay, i understand titles starting with letters

    and i understand titles starting with numbers

    what i was interested in seeing examples of was titles that satisfied what you said earlier - "I would like it to Select titles with either numbers or letters but not both"

    titles that start with letters --
    Code:
    select foo from bar where qux regexp '^[[:alpha:]]'
    titles that start with numbers --
    Code:
    select foo from bar where qux regexp '^[[:digit:]]'
    titles that start with neither a letter nor a number --
    Code:
    select foo from bar where qux regexp '^[^[:alnum:]]'
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •