SQL WHERE Clause
SQL WHERE clause is basically use for fetching specific criteria matched data only return. SQL WHERE clause is optionally clause in DML statement.
SQL WHERE clause we can use with SELECT, UPDATE, DELETE statements. SELECT statement with WHERE clause execute, fetching all table rows and apply WHERE clause filtering and finally return the result data.
Notes: You can't use INSERT statement with WHERE clause. But you can use INSERT Statement with WHERE cause only when you get the filter data from another TABLE.
WHERE clause use with SELECT Statement
When you get table data with specific filtered data, you should use where clause, considering following syntax that help you to understanding WHERE clause.
Syntax
SELECT * FROM table_name WHERE condition;
Example
SQL> SELECT * FROM users_info WHERE name = 'Opal Kole';
NO NAME ADDRESS CONTACT_NO
--- ------------------- --------------------------- --------------
1 Opal Kole 63 street Ct. 000-444-7847
WHERE clause use with UPDATE Statement
When you want to update specific table data you should use UPDATE statement with where clause. You can update/set more than one columns value.
Syntax
Considering following syntax that help you to understanding WHERE clause,
UPDATE table_name SET column_name=value1, ... WHERE condition;
Example
SQL> UPDATE users_info SET address = '145 Taxo court.' WHERE no = 10;
1 row updated.
WHERE clause use with DELETE Statement
When you want to delete specific table row(s) you should use DELETE statement with WHERE clause, Considering following syntax that help you to understanding WHERE clause.
Syntax
DELTE FROM table_name WHERE condition;
Example
SQL> DELETE FROM users_info WHERE no = 10;
1 row deleted.
WHERE clause use with INSERT Statement
When you want to insert filter data from another table, you should use INSERT statement with WHERE clause, Considering following syntax that help you to understanding WHERE clause,
Syntax
INSERT INTO table_name (column_name1, column_name2, ...)
SELECT column_name1, column_name2, ...
FROM another_table_name
WHERE condition;
Example
SQL> INSERT INTO userinfo (no, name, address)
SELECT no, name, address
FROM users_info
WHERE no = 1;
1 row inserted.
WHERE clause Operators
You can use WHERE clause with following operators.
Operator | Description | Example |
---|---|---|
= | Equal to |
|
<> | Not equal |
|
> | Greater than |
|
< | Less than |
|
>= | Greater than or equal |
|
<= | Less than or equal |
|
BETWEEN | Fetching within range data |
|
LIKE | Search for a pattern |
|
IN | Allows only specified values |
|
NOT IN | Not allows specified values |
|