SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast hopstream's Avatar
    Join Date
    Oct 2002
    Location
    Earth (directions: take a right from mars)
    Posts
    98
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question SQL Question... string comparison

    Here a short, quick question:

    I have a string field (store_name). I want to write two queries: one that selects all stores whose name starts with a letter; the second query selects all stores whose name starts with a number.

    Would the following query work for this? Is there a better way of doing this?
    Code:
    Query 1 (names that start with a letter):
    
    SELECT *
    FROM merchant_coupons
    WHERE 0 = SUBSTRING(name,1,1)
    
    
    Query 2 (names that start with a number):
    SELECT *
    FROM merchant_coupons
    WHERE 0 != SUBSTRING(name,1,1)

  2. #2
    SitePoint Enthusiast hopstream's Avatar
    Join Date
    Oct 2002
    Location
    Earth (directions: take a right from mars)
    Posts
    98
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I got the answer at another forum:

    SELECT * FROM merchant_coupons WHERE name REGEXP '^[a-zA-Z]'

    and

    SELECT * FROM merchant_coupons WHERE name REGEXP '^[0-9]'


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
  •