| SELECT | ENAME,JOB,SAL |
| FROM | EMP |
| WHERE | SAL >= 2000 |
By placing a conditional expression after the WHERE clause, only records that match the condition can be selected. the comparison operators that can be used for the WHERE condition are
| = | The left-hand side is equal to the right-hand side |
| < | left-hand side is smaller than right-hand side |
| <= | the left side is less than the right side |
| > | left-hand side is greater than right-hand side |
| >= | the left side is greater than the right side |
| <> | The left and right sides are not equal. |
Now for the Practice, I will give you two questions.
| SELECT | ENAME,JOB,SAL |
| FROM | EMP |
| WHERE | JOB = 'CLERK' AND SAL >= 1000 |
Use logical operators to select records by compound conditions.
| AND | and |
| OR | or |
| NOT | not |
If JOB = 'CLERK' AND SAL >= 1000, then the records that satisfy the conditions JOB = 'CLERK' and SAL >= 1000 are selected. To negate a conditional expression, put NOT in front of the expression, for example, NOT JOB = 'CLERK'.
Logical operators have precedence, and operations are performed in the order of NOT, AND, and OR. (parentheses) can be used to prioritize operations.
Now for the Practice, I will give you two questions.
| No | Name | English | Japanese | Math |
|---|---|---|---|---|
| 3011 | Sato | 56 | 70 | 60 |
| 2023 | Suzuki | 70 | 65 | 80 |
| 3047 | Tanaka | 80 | 70 | 50 |
| 3066 | Nakamura | 70 | 80 | 75 |
| A | SELECT No FROM grades WHERE English > 65 OR Japanese > 65 OR Math > 65 |
| B | SELECT No FROM grades WHERE English >= 65 AND Japanese >= 65 AND Math >= 65 |
| C | SELECT Name FROM grades WHERE English >= 65 OR Japanese >= 65 OR Math >= 65 |
| D | SELECT Name FROM grades WHERE English + Japanese + Math > 195 |
| E | SELECT Name FROM grades WHERE English + Japanese + Math >= 195 |
This concludes [Basics of SELECT statement (2)].