SQL WHERE Clause
- To limit the number of rows use the WHERE clause.
- The WHERE clause filters for rows that meet certain criteria.
- WHERE is followed by a condition that returns either true or false.
- WHERE is used with SELECT, UPDATE, and DELETE.
The SQL WHERE syntax
A WHERE clause with a SELECT statement:
- SELECT column-names FROM table-name WHERE condition
A WHERE clause with an UPDATE statement:
- UPDATE table-name SET column-name = value WHERE condition
A WHERE clause with a DELETE statement:
- DELETE table-name WHERE condition
SQL WHERE Clause Examples
1) with a select statementmysql> select name from person where age=26;
+-----------------+
| name |
+-----------------+
| shantanu biswas |
| sudip saha |
+-----------------+
2 rows in set (0.00 sec)
2) with an update statement
mysql> update person set sex='M' where age=25;
Query OK, 0 rows affected (0.00 sec)
Rows matched: 1 Changed: 0 Warnings: 0
Query OK, 0 rows affected (0.00 sec)
Rows matched: 1 Changed: 0 Warnings: 0
Comments
Post a Comment