SQL SELECT between clause

The syntax for using the BETWEEN clause in a SELECT statement is as follows:

SELECT column_name(s)
FROM table_name
WHERE column_name BETWEEN value1 AND value2;

Here’s a breakdown of each part of the syntax:

To illustrate this with an example, let’s say we have a table called employees with columns id, name, and salary. If we want to select employees with salaries between $50,000 and $100,000, the SQL query would look like this:

SELECT id, name, salary
FROM employees
WHERE salary BETWEEN 50000 AND 100000;

This query will retrieve the id, name, and salary of employees whose salary falls within the specified range.

Using the BETWEEN clause can be quite useful when you want to narrow down your search by specifying a range of values. However, keep in mind that the BETWEEN clause includes both the lower and upper bounds, so you need to be careful to choose the appropriate values for your condition.

#sql #between