Using XOR to link two conditions : XOR : Logic Operator MySQL TUTORIALS


MySQL TUTORIALS » Logic Operator » XOR »

 

Using XOR to link two conditions


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.03 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.navioo.com', 'Fiction',    6,  35),
    ->                          (106'Perl',           'Fiction',    2814),
    ->                          (107'Php',             NULL,        463);
Query OK, rows affected (0.01 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.navioo.com | Fiction    |       |      35 |
|    106 | Perl           | Fiction    |      28 |      14 |
|    107 | Php            | NULL       |      46 |       |
+--------+----------------+------------+---------+---------+
rows in set (0.00 sec)

mysql>
mysql>
mysql> SELECT BookName, Category, InStock, OnOrder
    -> FROM Books
    -> WHERE Category='Fiction' XOR InStock IS NULL
    -> ORDER BY BookName;
+----------------+----------+---------+---------+
| BookName       | Category | InStock | OnOrder |
+----------------+----------+---------+---------+
| MySQL          | Fiction  |      17 |      20 |
| Perl           | Fiction  |      28 |      14 |
| www.navioo.com | Fiction  |       |      35 |
+----------------+----------+---------+---------+
rows in set (0.00 sec)

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

mysql>



Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .

Follow Navioo On Twitter

MySQL TUTORIALS

 Navioo Logic Operator
» XOR