SQL between conditional statement usage

Source: Internet
Author: User

The BETWEEN condition allows you to retrieve a range of values.

The syntax for between is:

The code is as follows Copy Code

SELECT columns
From tables
WHERE column1 between value1 and value2;

Instance

The code is as follows Copy Code

SELECT *
From suppliers
WHERE supplier_id between 5000 and 5010;

When they can be judged by other

The code is as follows Copy Code

SELECT *
From suppliers
WHERE supplier_id >= 5000
and supplier_id <= 5010;

Action on a date

instance to find the data between the two dates

The code is as follows Copy Code

SELECT *
From Orders
WHERE order_date between To_date (' 2003/01/01 ', ' yyyy/mm/dd ')
and To_date (' 2003/12/31 ', ' yyyy/mm/dd ');


Another way

The code is as follows Copy Code

SELECT *
From Orders
WHERE order_date >= to_date (' 2003/01/01 ', ' yyyy/mm/dd ')
and order_date <= to_date (' 2003/12/31 ', ' yyyy/mm/dd ');


Instance three not between

The code is as follows Copy Code

SELECT *
From suppliers
WHERE supplier_id not between 5000 and 5500;

Another way

  code is as follows copy code

SELECT *
From suppliers
WHERE supplier_id < 5000
OR supplier_id > 5500;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.