On the previous page, we see where directives can be used to conditionally select data from a table. This condition may be simple (like the previous page example). may also be complex.
A complex condition is a connection of two or more simple conditions through and OR OR. There can be an infinite number of simple conditions in an SQL statement.
The syntax for complex conditions is as follows:
Select "Field name"
From "Table name"
WHERE "Simple Condition"
{[And|or] "simple condition"}+;
{}+ represents one or more occurrences within {}.}
What this means here is that the condition of and plus simple conditions and or plus simple conditions can occur one or more times. In addition, we can use () to represent the order of the conditions.
For example, if we want to select all the sales above $1,000 or sales between $ store_information and $275 in the table,
store_information Form
| Store_name |
Sales |
Txn_date |
| Los Angeles |
1500 |
05-jan-1999 |
| San Diego |
250 |
07-jan-1999 |
| San Francisco |
300 |
08-jan-1999 |
| Boston |
700 |
08-jan-1999 |
We'll break in,
SELECT Store_name
From Store_information
WHERE Sales > 1000
or (Sales < sales > 275);
Results:
| Store_name |
| Los Angeles |
| San Francisco |
Linux Real results:
Reprint please specify: Xiao Liu
A concise tutorial of SQL statements for Linux---and OR