SQL WHERE clause

The WHERE clause is used to specify selection criteria.
WHERE clause
To conditionally select data from a table, add a WHERE clause to the SELECT statement.
Syntax
SELECT column name FROM table name WHERE column operator value
The following operators can be used in the WHERE clause:
operator description
= equal to
<> not equal to
> greater than
< less than
>= greater than or equal to
<= less than or equal to
BETWEEN in a range Search for a pattern within
LIKE
Note : In some versions of SQL, the operator <> can be written as !=.
Using the WHERE clause
If we only want to select people who live in the city "Beijing", we need to add a WHERE clause to the SELECT statement:
SELECT * FROM Persons WHERE City='Beijing'
"Persons"




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 quotation
marks Note that we used single quotation marks around the conditional value in our example.
SQL uses single quotes to surround text values ​​(most database systems also accept double quotes). If it's a number, don't use quotes.
Text value:
This is correct:
SELECT * FROM Persons WHERE FirstName='Bush'

This is wrong:
SELECT * FROM Persons WHERE FirstName=Bush
Numerical value:
This is correct:
SELECT * FROM Persons WHERE Year>1965

This is wrong :
SELECT * FROM Persons WHERE Year>'1965'

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326557381&siteId=291194637