And/Or and Between Conditions


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>

Where, Like   < <  PREVIOUS   Table of Contents NEXT  > >   Distinct, Order By

Developed with HTML-Kit
Sandersongs Web Tutorials
Contact the Webmasterwith comments.
©2024, by Bill Sanders, all rights reserved.
This domain had 3,469 different visits in the last 30 days.
http://www.sandersongs.com/PHPsqlCourse/SQL08.php
This page was last modified on our server on 11 Jul 2021
and last refreshed on our server at 12:48 am, UTC
This file took 0.02186 seconds to process.