SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast Adelante's Avatar
    Join Date
    Sep 2006
    Location
    Queensland Australia
    Posts
    55
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How do you query a range of letters

    I'm a little bit stuck on a query, I want to get a range of records where the first letter of the field is between A-C and D-F ... A-Z,

    I've tried the between operator but find that records with the last letter of the range are omitted. No problem I thought just extend the range to the next letter but what happens when I get to the letter Z?

    This is the query I'm using:

    Code:
    SELECT *
    FROM exhibitors WHERE exhibitors.program BETWEEN 'A%' AND 'C%' ORDER BY exhibitors.program
    Is there another way to include every record in the range?

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,273
    Mentioned
    60 Post(s)
    Tagged
    3 Thread(s)
    you shouldn't have those wildcard percents in there, those are only for LIKE comparisons

    try this --

    WHERE exhibitors.program >= 'A' AND exhibitors.program < 'D' -- gives A to C inclusive

    WHERE exhibitors.program >= 'D' AND exhibitors.program < 'G' -- gives D to F inclusive

    WHERE exhibitors.program >= 'W' -- gives W to Z inclusive

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Enthusiast Adelante's Avatar
    Join Date
    Sep 2006
    Location
    Queensland Australia
    Posts
    55
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Rudy, that makes perfect sense, problem solved.


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
  •