And/Or Conditions
The AND operator displays a row if ALL conditions listed are true. The OR operator displays a row if ANY of the conditions listed are true. Finally, by using parentheses, you can combine both AND and OR clauses. Try it.
mysql> select * from people
-> where NAME_LAST = 'Jones' and POSITION = 'Manager';
+--------+-----------+------------+----+----------+ | ID | NAME_LAST | NAME_FIRST | MI | POSITION | +--------+-----------+------------+----+----------+ | rjones | Jones | Robert | T | Manager | +--------+-----------+------------+----+----------+1 row in set (0.00 sec) mysql> mysql> select * from people -> where NAME_LAST = 'Jones' or POSITION = 'Manager';
+--------+-----------+------------+----+------------+ | ID | NAME_LAST | NAME_FIRST | MI | POSITION | +--------+-----------+------------+----+------------+ | rjones | Jones | Robert | T | Manager | | tjones | Jones | Tyler | R | Technician | | nsmith | Smith | Nancy | B | Manager | +--------+-----------+------------+----+------------+3 rows in set (0.00 sec) mysql>select * from people -> where (NAME_LAST = 'Jones' or NAME_LAST = 'Smith') -> and POSITION = 'Manager';
+--------+-----------+------------+----+----------+ | ID | NAME_LAST | NAME_FIRST | MI | POSITION | +--------+-----------+------------+----+----------+ | rjones | Jones | Robert | T | Manager | | nsmith | Smith | Nancy | B | Manager | +--------+-----------+------------+----+----------+2 rows in set (0.00 sec) mysql>
BETWEEN Condition
The BETWEEN Condition selects an inclusive range of data between two values. These values can be numbers, text, or dates. If the values are text, it is an alphabetical selection. The NOT operator selects everything that is not between. Try it.
mysql> select ID, NAME_LAST from people
-> where NAME_LAST between 'Madison' and 'Williamson';
+--------+-----------+ | ID | NAME_LAST | +--------+-----------+ | bsmith | Smith | | nsmith | Smith | +--------+-----------+2 rows in set (0.02 sec) mysql> select ID, NAME_LAST from people -> where NAME_LAST not between 'Madison' and 'Williamson';
+--------+-----------+ | ID | NAME_LAST | +--------+-----------+ | rjones | Jones | | tjones | Jones | +--------+-----------+2 rows in set (0.00 sec) mysql>