PostgreSQL – BETWEEN operator
PostgreSQL BETWEEN operator is used to match a value against a range of values.
Syntax: value BETWEEN low AND high;
Syntax: value >= low and value;
The BETWEEN operator is used generally with WHERE clause with association with SELECT, INSERT, UPDATE or DELETE statement.
For the sake of this article we will be using the sample DVD rental database, which is explained here and can be downloaded by clicking on this link in our examples.
Here we will query for the payment whose amount is between 3 USD and 5 USD, using the BETWEEN operator in the “Payment” table of our sample database.
amount BETWEEN 3
Here we will query for getting the payment whose payment date is between 2007-02-07 and 2007-02-15 using the BETWEEN operator in the “Payment” table of our sample database.
payment_date BETWEEN '2007-02-07'
Note: While making date queries the literal date in ISO 8601 format i.e., YYYY-MM-DD should be used in PostgreSQL.
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses
are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!