Logical operator with parenthesis : Introduction « Logic Operator « MySQL Tutorial

Home
MySQL Tutorial
1.Introduction
2.Select Query
3.Database
4.Table
5.Table Join
6.Subquery
7.Insert Update Delete
8.Logic Operator
9.View
10.Data Types
11.Procedure Function
12.Cursor
13.Trigger
14.Date Time Functions
15.Comparison Functions Operators
16.Aggregate Functions
17.Cast Functions Operators
18.Control Flow Functions
19.Encryption Compression Functions
20.Information Functions
21.Math Numeric Functions
22.Miscellaneous Functions
23.String Functions
24.Regular Expressions
25.Data Dictionary
26.MySQL Utilities
27.Privilege
MySQL Tutorial » Logic Operator » Introduction 
8.1.2.Logical operator with parenthesis
mysql>
mysql>
mysql> CREATE TABLE Books(
    ->    BookID SMALLINT NOT NULL PRIMARY KEY,
    ->    BookName VARCHAR(40NOT NULL,
    ->    Category VARCHAR(15),
    ->    InStock SMALLINT NOT NULL,
    ->    OnOrder SMALLINT NOT NULL
    -> );
Query OK, rows affected (0.01 sec)

mysql>
mysql>
mysql> INSERT INTO Books VALUES (101'Java',           'Nonfiction', 1213),
    ->                          (102'MySQL',          'Fiction',    1720),
    ->                          (103'Oracle',         'Nonfiction', 2333),
    ->                          (104'VB.net',         'Nonfiction', 3212),
    ->                          (105'www.java2s.com', 'Fiction',    6,  35),
    ->                          (106'Perl',           'Fiction',    2814),
    ->                          (107'Php',             NULL,        463);
Query OK, rows affected (0.00 sec)
Records: 7  Duplicates: 0  Warnings: 0

mysql>
mysql>
mysql> select from Books;
+--------+----------------+------------+---------+---------+
| BookID | BookName       | Category   | InStock | OnOrder |
+--------+----------------+------------+---------+---------+
|    101 | Java           | Nonfiction |      12 |      13 |
|    102 | MySQL          | Fiction    |      17 |      20 |
|    103 | Oracle         | Nonfiction |      23 |      33 |
|    104 | VB.net         | Nonfiction |      32 |      12 |
|    105 | www.java2s.com | Fiction    |       |      35 |
|    106 | Perl           | Fiction    |      28 |      14 |
|    107 | Php            | NULL       |      46 |       |
+--------+----------------+------------+---------+---------+
rows in set (0.00 sec)

mysql>
mysql> SELECT BookName, Category, InStock, OnOrder
    -> FROM Books
    -> WHERE InStock>20 AND (Category IS NULL OR NOT (Category='Fiction'))
    -> ORDER BY BookName;
+----------+------------+---------+---------+
| BookName | Category   | InStock | OnOrder |
+----------+------------+---------+---------+
| Oracle   | Nonfiction |      23 |      33 |
| Php      | NULL       |      46 |       |
| VB.net   | Nonfiction |      32 |      12 |
+----------+------------+---------+---------+
rows in set (0.00 sec)

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

mysql>
8.1.Introduction
8.1.1.Logical Operators
8.1.2.Logical operator with parenthesis
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.