[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2214
  • Last Modified:

SQL Select between letters R and Z

I'm trying to use

Select title from mylist where title between 'r' and 'z'

It selects all the r's but I dont see any title beginning with 'z'.
How do I make this command inclusive for the last letter as well?
0
arthurh88
Asked:
arthurh88
  • 2
  • 2
1 Solution
 
Kent OlsenData Warehouse Architect / DBACommented:
Hi Arthur,

"between" is inclusive of the two delimiters.  In your example, all of the letters between 'r' and 'z', including 'r' and 'z'.

I suspect that any title that starts with 'z' is more than once character in length.  In that case, the name would not be between 'r' and 'z' as the sort order would place it after 'z'.

Try this:

  where substring (title, 1, 1) between 'a' and 'z'.


You might next stumble onto a case issue.  If so, make sure that you call the lower() function on the first character of the title.

  where lower (substring (title, 1, 1)) between 'a' and 'z'.


Good Luck,
Kent
0
 
IrogSintaCommented:
You can also do something like this:
between 'r' and 'zzzzz'

Ron
0
 
arthurh88Author Commented:
yes that worked awesome.   between 'a' and 'ezz'  thanks!
0
 
Kent OlsenData Warehouse Architect / DBACommented:
I hate to see people use the wrong solution because it codes easier.

As soon as you have a title that starts with 'ezzanything' that doesn't work.  Nor does it work if the title contains mixed case letters.  It may work in this one specific application, but it's a poor habit to get into.
0
 
IrogSintaCommented:
@arthurh88
You should have used a few more z's just in case you do have a title that starts with ezz.  In addition, if you're titles are in both Upper and Lower case, you will run into a problem.  You should add the Lower function to your Where condition as Kdo said.

The benefit of using zzzzz's in a range is that it allows you to define your delimiters more specifically such as shown below:

BEG_RANGE      END_RANGE
AAAAAAAAAA      GLIDZZZZZZ
GLIEAAAAAA          POGUZZZZZZ
POGVAAAAAA        ZZZZZZZZZZ
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now