Range check with between ... and : Between « Function « SQL / MySQL

Home
SQL / MySQL
1.Aggregate Functions
2.Backup Load
3.Command MySQL
4.Cursor
5.Data Type
6.Database
7.Date Time
8.Engine
9.Event
10.Flow Control
11.FullText Search
12.Function
13.Geometric
14.I18N
15.Insert Delete Update
16.Join
17.Key
18.Math
19.Procedure Function
20.Regular Expression
21.Select Clause
22.String
23.Table Index
24.Transaction
25.Trigger
26.User Permission
27.View
28.Where Clause
29.XML
SQL / MySQL » Function » Between 
Range check with between ... and
      
mysql>
mysql> CREATE TABLE IF NOT EXISTS product
    -> (
    ->   code           CHAR(8)         PRIMARY KEY,
    ->   make           VARCHAR(25)     NOT NULL,
    ->   model          VARCHAR(25)     NOT NULL,
    ->   price          INT             NOT NULL
    -> );
Query OK, rows affected (0.00 sec)

mysql>
mysql> # insert records into the "product" table
mysql> INSERT INTO product (code, make, model, price)   VALUES ("335/1914""York""Pacer 2120"159);
Query OK, row affected (0.00 sec)

mysql> INSERT INTO product (code, make, model, price)   VALUES ("335/1907""York""Pacer 2750"349);
Query OK, row affected (0.00 sec)

mysql> INSERT INTO product (code, make, model, price)   VALUES ("335/1921""York""Pacer 3100"499);
Query OK, row affected (0.00 sec)

mysql> INSERT INTO product (code, make, model, price)   VALUES ("335/2717""Proform""7.25Q"799);
Query OK, row affected (0.00 sec)

mysql> INSERT INTO product (code, make, model, price)   VALUES ("335/2652""Reebok""TR1 Power Run"895);
Query OK, row affected (0.00 sec)

mysql>
mysql> # show all records where the price is between 300 500
mysql> SELECT FROM product WHERE price BETWEEN 300 AND 500;
+----------+------+------------+-------+
| code     | make | model      | price |
+----------+------+------------+-------+
335/1907 | York | Pacer 2750 |   349 |
335/1921 | York | Pacer 3100 |   499 |
+----------+------+------------+-------+
rows in set (0.00 sec)

mysql>
mysql> # show records where the make is between "Proform" and "York"
mysql> SELECT FROM product WHERE make BETWEEN "P" AND "Y";
+----------+---------+---------------+-------+
| code     | make    | model         | price |
+----------+---------+---------------+-------+
335/2717 | Proform | 7.25Q         |   799 |
335/2652 | Reebok  | TR1 Power Run |   895 |
+----------+---------+---------------+-------+
rows in set (0.00 sec)

mysql>
mysql> # delete this sample table
mysql> DROP TABLE IF EXISTS product;
Query OK, rows affected (0.00 sec)

mysql>

   
    
    
    
    
    
  
Related examples in the same category
1.Use BETWEEN AND for int value
2.Use IN and BETWEEN AND
3.Where clause: NOT BETWEEN
4.Selecting Records Based on Their Temporal Characteristics
5.Between ... and vs and
6.Integer value and between...and
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.