SQL’s Between Range

We have previously found the minimum and maximum range for a price column in a table.

But what if we wanted to find the values in between? Say for example you wanted to view all the products you sell between $50 and $100 dollars?

SELECT * FROM products WHERE price BETWEEN 50 AND 100;

See how easy that is, it almost reads like a normal sentence, this is why SQL is considered to have natural language syntax.

Now, the between operator can also be used to find in a range of letters.

For example, if we have a table of employees and a column with employee last names, and we wanted to find all the employees whose last names range from a-m, we would do a query like this:

SELECT * FROM employees WHERE lastname BETWEEN a AND m;

Easy as pie.

Bookmark it and Share These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Netvouz
  • DZone
  • ThisNext
  • BlinkList
  • Bumpzee
  • De.lirio.us
  • Furl
  • Ma.gnolia
  • NewsVine
  • Reddit
  • Spurl
  • StumbleUpon
  • Technorati
  • YahooMyWeb
No related posts

1 Comment so far

  1. Ahmad on March 18th, 2008

    I was trying to understand the difference with this versus using max and min.

Leave a reply