Simple SQL question - LIKE operator

Discussion in 'Programming' started by lespaul00, Jan 14, 2008.

  1. #1
    For the following query, all results that start with A will be returned:

    <cfquery name="type" datasource="mydatabase">
    SELECT RECIPE_ID, RECIPE_NAME, LINK
    FROM   TBLRECIPES
    WHERE RECIPE_NAME LIKE 'A%'
    ORDER BY RECIPE_NAME
    </cfquery>
    Code (markup):
    I would like to make it so it returns all recipes that begin with a number. Is the only way to do this as such:?

    <cfquery name="type" datasource="mydatabase">
    SELECT RECIPE_ID, RECIPE_NAME, LINK
    FROM   TBLRECIPES
    WHERE RECIPE_NAME LIKE '1%' OR '2%' ..etc...
    ORDER BY RECIPE_NAME
    </cfquery>
    Code (markup):
     
    lespaul00, Jan 14, 2008 IP
  2. cfStarlight

    cfStarlight Peon

    Messages:
    398
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You'll have to look in your database's documentation. IIRC some db's support ranges such as LIKE '[0-9]%' or regular expression matching, but you'd have to check your documentation to know for certain.
     
    cfStarlight, Jan 14, 2008 IP
  3. lespaul00

    lespaul00 Peon

    Messages:
    283
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    It does support ranges. I tried it, and it worked. I saw the range function in the literature, but didn't know how it was applied... looking at your example, it makes sense. Thanks.
     
    lespaul00, Jan 15, 2008 IP