The BETWEEN condition determines whether the value of one expression is in an interval of two other expressions.
Between example
COURSE_ID |
NAME |
DESCRIPTION |
DURATION |
PRICE |
1 |
SQL 1 |
SQL course for beginners |
1 week |
10 |
2 |
SQL 2 |
SQL course for advanced |
2 week |
50 |
3 |
HTML5 |
Learn HTML 5 |
1 week |
10 |
4 |
PHP |
PHP course |
4 week |
75 |
5 |
CSS |
Learn CSS |
2 week |
20 |
SELECT * FROM course WHERE price BETWEEN 20 AND 50;
Output
COURSE_ID |
NAME |
DESCRIPTION |
DURATION |
PRICE |
2 |
SQL 2 |
SQL course for advanced |
2 week |
50 |
5 |
CSS |
Learn CSS |
2 week |
20 |
Between example
ORDER_ID |
COURSE_ID |
STUDENT_ID |
ORDER_DATE |
1 |
1 |
6 |
07-AUG-2014 10:11:03 |
2 |
5 |
7 |
23-SEP-2014 12:31:41 |
3 |
4 |
5 |
29-AUG-2014 09:55:54 |
21 |
5 |
6 |
01-DEC-2014 16:32:36 |
22 |
1 |
4 |
17-DEC-2014 17:22:27 |
SELECT * FROM orders WHERE order_date BETWEEN '01-AUG-2014' AND '01-OCT-2014';
Output
ORDER_ID |
COURSE_ID |
STUDENT_ID |
ORDER_DATE |
1 |
1 |
6 |
07-AUG-2014 10:11:03 |
2 |
5 |
7 |
23-SEP-2014 12:31:41 |
3 |
4 |
5 |
29-AUG-2014 09:55:54 |
SELECT * FROM orders
WHERE order_date BETWEEN TO_DATE('01-12-2014','DD-MM-YYYY') AND TO_DATE('31-12-2014','DD-MM-YYYY');
Output
ORDER_ID |
COURSE_ID |
STUDENT_ID |
ORDER_DATE |
21 |
5 |
6 |
01-DEC-2014 16:32:36 |
22 |
1 |
4 |
17-DEC-2014 17:22:27 |