Home > Database > Mysql Tutorial > body text

How to use the WHERE clause in SQL to specify selection criteria

王林
Release: 2023-06-03 16:31:12
forward
1065 people have browsed it

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 列 运算符 值
Copy after login

The following operators can be used in the WHERE clause:
=: equal to
<>: not equal to
>: greater than
<: Less than
>=: 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 <> 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"
Copy after login

"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
Copy after login

Result:

LastName    FirstName    Address            City        Year
Carter      Thomas       Changan Street     Beijing     1980
Gates       Bill         Xuanwumen 10       Beijing     1985
Copy after login


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
Copy after login

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!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!