Use an XOR logical operator between two expressions in an SQL statement
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.01 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>
mysql> SELECT BookName, Category, InStock, OnOrder
-> FROM Books
-> WHERE Category='Fiction' XOR InStock IS NULL
-> ORDER BY BookName;
+-------------------------------+----------+---------+---------+
| BookName | Category | InStock | OnOrder |
+-------------------------------+----------+---------+---------+
| One Hundred Years of Solitude | Fiction | 28 | 14 |
| Oracle | Fiction | 17 | 20 |
| Pascal | Fiction | 6 | 35 |
+-------------------------------+----------+---------+---------+
3 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