Publishers of technology books, eBooks, and videos for creative people

Home > Blogs > Specifying endpoints for BETWEEN expressions, Five SQL Tips in Five Days, Part 3

Specifying endpoints for BETWEEN expressions, Five SQL Tips in Five Days, Part 3

By  Jul 23, 2008

Topics: Productivity

Specifying a character range for a BETWEEN expression often needs some thought.

Suppose you want to search for last names that begin with the letter F.

The following clause won't work because it will retrieve someone whose last name is the letter G (is the letter G, not starts with the letter G):

WHERE last_name BETWEEN 'F' AND 'G'

This next clause shows the correct way to specify the ending point (in most cases):

WHERE last_name BETWEEN 'F' AND 'Fz' 

Check back here each day this week for more SQL tips.

And for more on SQL, be sure to check out my book SQL: Visual QuickStart Guide, 3rd Edition.