ylbtech-SQL-W3School: SQL WHERE statement |
1. Back to top |
1、
WHERE clause for selection standards.
WHERE clause
To conditionally select data from the table , can be added to the WHERE clause of a SELECT statement.
grammar
SELECT column names FROM table name WHERE column operator value
The following operators can be used in the WHERE clause:
Operators | description |
---|---|
= | equal |
<> | not equal to |
> | more than the |
< | Less than |
>= | greater or equal to |
<= | Less than or equal |
BETWEEN | Within a certain range |
LIKE | Search a pattern |
Note: In some versions of SQL, the operator <> can be written as =! .
Using the WHERE clause
If you only want to select people living in the city "Beijing" in, we need to add a WHERE clause to the SELECT statement:
SELECT * FROM Persons WHERE City='Beijing'
"Persons" 表
LastName | FirstName | Address | City | Year |
---|---|---|---|---|
Adams | John | Oxford Street | London | 1970 |
Bush | George | Fifth Avenue | New York | 1975 |
Carter | Thomas | Changan Street | Beijing | 1980 |
Gates | Bill | Xuanwumen 10 | Beijing | 1985 |
result:
LastName | FirstName | Address | City | Year |
---|---|---|---|---|
Carter | Thomas | Changan Street | Beijing | 1980 |
Gates | Bill | Xuanwumen 10 | Beijing | 1985 |
Use of quotes
Please note that we value in case the conditions of use is surrounded by single quotes.
SQL uses single quotes surround text values (most database systems also accept double quotes). If the value, do not use quotation marks .
Text Value:
this is correct: SELECT * FROM Persons WHEREFirstName='Bush'
This is wrong: SELECT * FROM Persons WHEREFirstName=Bush
Value:
this is correct: SELECT * FROM Persons WHEREYear>1965
This is wrong: SELECT * FROM Persons WHEREYear>'1965'
2、
2. Return to top |
3. Back to top |
4. Top |
5. Top |
1、
2、
6. Back to top |
Author: ylbtech Source: http://ylbtech.cnblogs.com/ This article belongs to the author and blog Park total, welcome to reprint, but without the author's consent declared by this section must be retained, and given the original connection in the apparent position of the article page, otherwise reserves the right to pursue legal responsibilities. |