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.
©2017, by Bill Sanders, all rights reserved.
This domain had 4,012 different visits in the last 30 days.
435,489 hits on this domain since 24 Nov 2006.
http://sandersongs.com/PHPsqlCourse/SQL08.php
This page was last modified on our server on 4 Jun 2008
and last refreshed on our server at 12:33 pm, MST
This file took 0.00867 seconds to process.