The best SQL WHERE clause Tutorial In 2024, In this tutorial you can learn SQL WHERE clause,The demo database,WHERE clause examples,Examples,Text field vs. a numeric field,Examples,WHERE clause operator,
WHERE clause is used to filter the records.
WHERE clause is used to extract records that meet the specified criteria.
In this tutorial, we will use w3big sample database.
The following is a selected "Websites" table data:
+----+--------------+---------------------------+-------+---------+ | id | name | url | alexa | country | +----+--------------+---------------------------+-------+---------+ | 1 | Google | https://www.google.cm/ | 1 | USA | | 2 | 淘宝 | https://www.taobao.com/ | 13 | CN | | 3 | 本教程 | http://www.w3write.com/ | 4689 | CN | | 4 | 微博 | http://weibo.com/ | 20 | CN | | 5 | Facebook | https://www.facebook.com/ | 3 | USA | +----+--------------+---------------------------+-------+---------+
The following SQL statement Select a country as "CN" from all the sites "Websites" table:
Execution output:
SQL uses single quotes to surround text values (most database systems also accept double quotes).
In the last instance 'CN' text field uses a single quote.
If it is a numeric field, do not use quotation marks.
Execution output:
The following operators can use in the WHERE clause:
Operators | description |
---|---|
= | equal |
<> | not equal to.NOTE: In some versions of SQL, the operator can be written as =! |
> | more than the |
< | Less than |
> = | greater or equal to |
<= | Less than or equal |
BETWEEN | Within a certain range |
LIKE | Search for a pattern |
IN | Specifies the possible values for a plurality of columns |