Home >Database >Mysql Tutorial >How to use the WHERE clause in SQL to specify selection criteria
SQL WHERE clause
The WHERE clause is used to specify the selection criteria.
To conditionally select data from a table, add a WHERE clause to the SELECT statement. The syntax is as follows:
SELECT 列名称 FROM 表名称 WHERE 列 运算符 值
The following operators can be used in the WHERE clause:
=: equal to
a8093152e673feb7aba1828c43532094: not equal to
>: greater than
94df8ccf225e1f8e0ac6804ed5273537=: Greater than or equal to
<=: Less than or equal to
BETWEEN: Within a certain range
LIKE: Search for a certain pattern
Note: In certain In versions of SQL, the operator a8093152e673feb7aba1828c43532094 can be written as !=.
Use WHERE clause
If you only want to select people living in the city "Beijing", we need to add a WHERE clause to the SELECT statement:
SELECT * FROM Persons WHERE City="Beijing"
"Persons" table
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 quotation marks
SQL uses single quotation marks to surround Text value (most database systems also accept double quotes). If it is a numeric value, no quotes are used.
SELECT * FROM Persons WHERE FirstName="Bush" SELECT * FROM Persons WHERE Year>1965
The above is the detailed content of How to use the WHERE clause in SQL to specify selection criteria. For more information, please follow other related articles on the PHP Chinese website!