SELECT statement includes two expressions within the WHERE clause : OR « Where Clause « SQL / MySQL






SELECT statement includes two expressions within the WHERE clause

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

mysql> INSERT INTO Books VALUES
    -> (101, 'C: Writing on Writing', 'Nonfiction', 12, 13),
    -> (102, 'Oracle', 'Fiction', 17, 20),
    -> (103, 'Opera', 'Nonfiction', 23, 33),
    -> (104, 'Notebook', 'Nonfiction', 32, 12),
    -> (105, 'Pascal', 'Fiction', 6, 35),
    -> (106, 'One Hundred Years of Solitude', 'Fiction', 28, 14),
    -> (107, 'Where I\'m Calling From', NULL, 46, 3);
Query OK, 7 rows affected (0.00 sec)
Records: 7  Duplicates: 0  Warnings: 0

mysql>
mysql>
mysql> SELECT BookName, Category, InStock, OnOrder
    -> FROM Books
    -> WHERE InStock>30 OR OnOrder>30
    -> ORDER BY BookName;
+------------------------+------------+---------+---------+
| BookName               | Category   | InStock | OnOrder |
+------------------------+------------+---------+---------+
| Notebook               | Nonfiction |      32 |      12 |
| Opera                  | Nonfiction |      23 |      33 |
| Pascal                 | Fiction    |       6 |      35 |
| Where I'm Calling From | NULL       |      46 |       3 |
+------------------------+------------+---------+---------+
4 rows in set (0.00 sec)

mysql>
mysql> drop table Books;
Query OK, 0 rows affected (0.00 sec)

   
    
    
    
    
    
  








Related examples in the same category

1.An OR operator
2.AND and OR may be intermixed
3.Combine conditions in select clause
4.Combine condition with OR
5.SELECT statement includes three expressions connected with an AND operator and an OR operator