PHP Tutorials
- What is MySqli
- mysql query
- mysql query example
- InnoDB
- mysql column Type
- CRUD Example
- Connection Using Function
- mysql keys
- SELECT
- WHERE
- UPDATE
- Count no of Rows
- ALIAS
- AND, AND & OR
- BETWEEN
- COMPARISON OPERATOR
- DELETE
- DELETE LIMIT
- DISTINCT
- EXISTS
- FROM
- GROUP BY
- HAVING
- IN
- INTERSECT
- IS NULL & IS NOT NULL
- LIKE
- NOT
- ORDER BY
- SELECT LIMIT
- SUBQUERY
- TRUNCATE
- UNION && UNION ALL
- Concat & Group_Concat
- mysql Function
- Mysql Insert Id
- MySql Aggregate Function
- Mysql Join
- JOIN in MySql
- Trigger
- Procedure
- Transaction
- views
- Index
- SQL Injection
- Normalization
- Query Bind
- Interview Questions
Important Link
BETWEEN Condition
MySQL BETWEEN Condition is used to retrieve values within a range in a SELECT, INSERT, UPDATE, or DELETE statement.
With Numeric
SELECT *
FROM contacts
WHERE contact_id BETWEEN 100 AND 200;
This MySQL BETWEEN example would return all rows from the contacts table where the contact_id is between 100 and 200 (inclusive).
It is equivalent to the following SELECT statement:
SELECT *
FROM contacts
WHERE contact_id >= 100
AND contact_id <= 200;
With Date
When using the BETWEEN condition in MySQL with dates, be sure to use the CAST function to explicitly convert the values to dates.
SELECT *
FROM order_details
WHERE order_date BETWEEN CAST('2014-02-01' AS DATE) AND CAST('2014-02-28' AS DATE);
It would be equivalent to the following SELECT statement:
SELECT *
FROM order_details
WHERE order_date >= CAST('2014-02-01' AS DATE)
AND order_date <= CAST('2014-02-28' AS DATE);
NOT Operator
SELECT *
FROM suppliers
WHERE supplier_id NOT BETWEEN 2000 AND 2999;
SELECT name,country,city,dob FROM users WHERE YEAR(dob) NOT BETWEEN 1984 AND 2000;
SELECT *
FROM suppliers
WHERE supplier_id < 2000
OR supplier_id > 2999;
SELECT name,country,city,date_of_birth
FROM users
WHERE MONTH(date_of_birth) BETWEEN '03' and '08';
1969-04-25
1985-10-01
1975-07-05
1984-09-02
1975-01-01
output :-
1969-04-25
1975-07-05
SELECT name,country,city,date_of_birth
FROM users
WHERE MONTH(date_of_birth) BETWEEN '05' AND '09'
AND YEAR(date_of_birth) BETWEEN 1950 AND 1975;
Not Between
The NOT BETWEEN Operator is just the opposite of BETWEEN Operator. NOT BETWEEN operator will return data where the column values not in between the range values.
SELECT * FROM customers WHERE Age NOT BETWEEN 18 AND 21;