Comparison operators 2 : Operator « Select Clause « 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 » Select Clause » Operator 
Comparison operators 2
      
mysql>
mysql> CREATE TABLE IF NOT EXISTS product
    -> (
    ->   code           CHAR(8)         PRIMARY KEY,
    ->   make           VARCHAR(25)     NOT NULL,
    ->   model          VARCHAR(25)     NOT NULL,
    ->   price          DECIMAL(3,2)    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 ("512/4792""Alba""C2108"6.75);
Query OK, row affected (0.00 sec)

mysql> INSERT INTO product (code, make, model, price)   VALUES ("512/4125""Hitachi""KC30"8.99);
Query OK, row affected (0.00 sec)

mysql> INSERT INTO product (code, make, model, price)   VALUES ("512/1458""Philips""AJ3010"19.99);
Query OK, row affected, warning (0.00 sec)

mysql> INSERT INTO product (code, make, model, price)   VALUES ("512/3669""Morphy Richards""28025"19.99);
Query OK, row affected, warning (0.00 sec)

mysql> INSERT INTO product (code, make, model, price)   VALUES ("512/1444""Sony""C253"29.49);
Query OK, row affected, warning (0.00 sec)

mysql>
mysql> # show records in "product" if price is below 19.99
mysql> SELECT FROM product WHERE price < 19.99;
+----------+-----------------+--------+-------+
| code     | make            | model  | price |
+----------+-----------------+--------+-------+
512/4792 | Alba            | C2108  |  6.75 |
512/4125 | Hitachi         | KC30   |  8.99 |
512/1458 | Philips         | AJ3010 |  9.99 |
512/3669 | Morphy Richards | 28025  |  9.99 |
512/1444 | Sony            | C253   |  9.99 |
+----------+-----------------+--------+-------+
rows in set (0.00 sec)

mysql>
mysql> # show records in "product" if price is above 19.99
mysql> SELECT FROM product WHERE price > 19.99;
Empty set (0.00 sec)

mysql>
mysql> # show records in "product" if price is 19.99 or less
mysql> SELECT FROM product WHERE price <= 19.99;
+----------+-----------------+--------+-------+
| code     | make            | model  | price |
+----------+-----------------+--------+-------+
512/4792 | Alba            | C2108  |  6.75 |
512/4125 | Hitachi         | KC30   |  8.99 |
512/1458 | Philips         | AJ3010 |  9.99 |
512/3669 | Morphy Richards | 28025  |  9.99 |
512/1444 | Sony            | C253   |  9.99 |
+----------+-----------------+--------+-------+
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.Comparison Operators
2.Arithmetic Operators
3.Sort Operators
4.special <=> operator, which is like = except that it works with NULL operands by treating them as any other va
5.Compare NULL with <=> operator
6.Not operator
7.or operator vs in operator
8.Comparison Operators and null
9.Use the basic mathematical operators
10.In operator and a long list of integer
11.Less than and equals(<=) operators with All operator
12.Reversing or Negating Query Conditions
13.Not equal
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.