Where clause: compare : Where « Where 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 » Where Clause » Where 
Where clause: compare
   
/*
mysql> Drop table Books;
Query OK, 0 rows affected (0.00 sec)

mysql> CREATE TABLE Books
    -> (
    ->    ID SMALLINT NOT NULL PRIMARY KEY,
    ->    Name VARCHAR(40) NOT NULL,
    ->    Category VARCHAR(15),
    ->    InStock SMALLINT NOT NULL,
    ->    OnOrder SMALLINT NOT NULL
    -> );
Query OK, 0 rows affected (0.04 sec)

mysql> INSERT INTO Books
    -> VALUES (101, 'On', 'Nonfiction', 13, 11),
    ->        (102, 'News', 'Fiction', 15, 21),
    ->        (103, 'Hello', 'Nonfiction', 21, 32),
    ->        (104, 'Poet', 'Nonfiction', 35, 13),
    ->        (105, 'Dunces', 'Fiction', 5, 35),
    ->        (106, 'One', 'Fiction', 28, 14),
    ->        (107, 'From', NULL, 46, 31);
Query OK, 7 rows affected (0.00 sec)
Records: 7  Duplicates: 0  Warnings: 0

mysql> select * from Books;
+-----+--------+------------+---------+---------+
| ID  | Name   | Category   | InStock | OnOrder |
+-----+--------+------------+---------+---------+
| 101 | On     | Nonfiction |      13 |      11 |
| 102 | News   | Fiction    |      15 |      21 |
| 103 | Hello  | Nonfiction |      21 |      32 |
| 104 | Poet   | Nonfiction |      35 |      13 |
| 105 | Dunces | Fiction    |       5 |      35 |
| 106 | One    | Fiction    |      28 |      14 |
| 107 | From   | NULL       |      46 |      31 |
+-----+--------+------------+---------+---------+
7 rows in set (0.00 sec)

mysql> SELECT Name, Category, InStock, OnOrder
    -> FROM Books
    -> WHERE InStock>30 OR OnOrder>30
    -> ORDER BY Name;
+--------+------------+---------+---------+
| Name   | Category   | InStock | OnOrder |
+--------+------------+---------+---------+
| Dunces | Fiction    |       5 |      35 |
| From   | NULL       |      46 |      31 |
| Hello  | Nonfiction |      21 |      32 |
| Poet   | Nonfiction |      35 |      13 |
+--------+------------+---------+---------+
4 rows in set (0.00 sec)


*/

Drop table Books;

CREATE TABLE Books
(
   ID SMALLINT NOT NULL PRIMARY KEY,
   Name VARCHAR(40NOT NULL,
   Category VARCHAR(15),
   InStock SMALLINT NOT NULL,
   OnOrder SMALLINT NOT NULL
);


INSERT INTO Books
VALUES (101'On', 'Nonfiction', 1311),
       (102'News', 'Fiction', 1521),
       (103'Hello', 'Nonfiction', 2132),
       (104'Poet', 'Nonfiction', 3513),
       (105'Dunces', 'Fiction', 535),
       (106'One', 'Fiction', 2814),
       (107'From', NULL, 4631);


select from Books;

SELECT Name, Category, InStock, OnOrder
FROM Books
WHERE InStock>30 OR OnOrder>30
ORDER BY Name;


           
         
    
    
  
Related examples in the same category
1.Not equal in where
2.Getting the List of Products That Are on Catalog Promotion
3.Using Where Conditions
4.WHERE Clause Comparisons
5.Combining WHERE Conditions
6.Calculation in WHERE clause
7.Compare and calculate in Where clause
8.Do Calculation in Where and order
9.Where clause: nested conditions
10.Where clause: calculation and equal condition
11.Where clause: XOR
12.Use where clause the narrow down results
13.Use CURRENT_DATE in where clause
14.WHERE TRUE OR FALSE
15.Change localhost to the name of the machine where you'll be working.
16.WHERE clauses can test multiple conditions.
17.To put first those records where people sent messages to themselves
18.Using a WHERE clause that matches up values in the author ID column
19.Add a WHERE clause that looks for NULL values in the book column that is named in the ON clause
20.Add an expression to the WHERE clause that explicitly excludes the reference
21.Adds an additional condition to the WHERE clause and the calculated columns must have a total greater than 20
22.A WHERE clause that contains two expressions (conditions)
23.Searches for surnames that have an e anywhere in the name and then end with an e:
24.Show all records where the color is "Silver" and the price is above 100.00
25.Show records where make is "Krups", "Gaggia" or "DeLonghi" and the model is not "TSK-182" or "EC410"
26.Show all records where the color is not "Silver" or the price is below 100.00
27.Get the number of items for each color where the price exceeds 150.00 and when there is more than 1 item for t
28.Check day name in where clause
29.Compare the results from two statements
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.