SQL WHERE AND, OR, NOT Clause
- WHERE conditions can be combined with AND, OR, and NOT.
- A WHERE clause with AND requires that two conditions are true.
- A WHERE clause with OR requires that one of two conditions is true.
- A WHERE clause with NOT negates the specified condition.
The WHERE with AND, OR, NOT syntax
A WHERE clause with AND:
- SELECT column-names FROM table-name WHERE condition1 AND condition2
A WHERE clause with OR:
- UPDATE table-name SET column-name = value WHERE condition1 OR condition2
A WHERE clause with NOT:
- DELETE table-name WHERE NOT condition
SQL WHERE with AND, OR, and NOT Examples
1) Example of AND Clause
mysql> select name from person where age>20 and Sex='M';
+-----------------+
| name |
+-----------------+
| subham ball |
| sajal |
| sourav biswas |
| sajal |
| chayan das |
| shantanu biswas |
+-----------------+
6 rows in set (0.00 sec)
+-----------------+
| name |
+-----------------+
| subham ball |
| sajal |
| sourav biswas |
| sajal |
| chayan das |
| shantanu biswas |
+-----------------+
6 rows in set (0.00 sec)
2) Example of OR Clause
mysql> select name from person where age>20 or sex='M';
+-----------------+
| name |
+-----------------+
| subham ball |
| jit |
| sajal |
| sourav biswas |
| sajal |
| chayan das |
| shantanu biswas |
| sudip saha |
| debo |
| monojit |
+-----------------+
10 rows in set (0.00 sec)
+-----------------+
| name |
+-----------------+
| subham ball |
| jit |
| sajal |
| sourav biswas |
| sajal |
| chayan das |
| shantanu biswas |
| sudip saha |
| debo |
| monojit |
+-----------------+
10 rows in set (0.00 sec)
Comments
Post a Comment