Show records where make is "Krups", "Gaggia" or "DeLonghi" and the model is not "TSK-182" or "EC410"
mysql>
mysql> CREATE TABLE IF NOT EXISTS product
-> (
-> id INT AUTO_INCREMENT PRIMARY KEY,
-> make VARCHAR(25) NOT NULL,
-> model VARCHAR(25) NOT NULL,
-> price DECIMAL(6,2) NOT NULL
-> );
Query OK, 0 rows affected (0.00 sec)
mysql>
mysql> # insert 5 records into the "product" table
mysql> INSERT INTO product (make, model, price) VALUES ("Cookworks", "TSK-182", 19.99);
Query OK, 1 row affected (0.00 sec)
mysql> INSERT INTO product (make, model, price) VALUES ("Morphy Richards", "Europa", 38.25);
Query OK, 1 row affected (0.00 sec)
mysql> INSERT INTO product (make, model, price) VALUES ("Krups", "Vivo", 79.50);
Query OK, 1 row affected (0.00 sec)
mysql> INSERT INTO product (make, model, price) VALUES ("DeLonghi", "EC410", 139.00);
Query OK, 1 row affected (0.00 sec)
mysql> INSERT INTO product (make, model, price) VALUES ("Gaggia", "DeLuxe", 199.00);
Query OK, 1 row affected (0.00 sec)
mysql>
mysql> # show all data in the "product" table
mysql> SELECT * FROM product;
+----+-----------------+---------+--------+
| id | make | model | price |
+----+-----------------+---------+--------+
| 1 | Cookworks | TSK-182 | 19.99 |
| 2 | Morphy Richards | Europa | 38.25 |
| 3 | Krups | Vivo | 79.50 |
| 4 | DeLonghi | EC410 | 139.00 |
| 5 | Gaggia | DeLuxe | 199.00 |
+----+-----------------+---------+--------+
5 rows in set (0.00 sec)
mysql>
mysql> SELECT * FROM product
-> WHERE make IN ("Krups", "Gaggia", "DeLonghi")
-> AND model NOT IN ("TSK-182", "EC410");
+----+--------+--------+--------+
| id | make | model | price |
+----+--------+--------+--------+
| 3 | Krups | Vivo | 79.50 |
| 5 | Gaggia | DeLuxe | 199.00 |
+----+--------+--------+--------+
2 rows in set (0.00 sec)
mysql>
mysql> # delete this sample table
mysql> DROP TABLE IF EXISTS product;
Query OK, 0 rows affected (0.00 sec)
mysql>
Related examples in the same category