SQL where clause

Time:2020-9-29

 

The where clause is used to specify the criteria for selection.


 

Where clause

To conditionally select data from a table, add where to the select statement.

Grammar:

 

Select column name from table name where column operator value

 

 

The following operators can be used in the where clause.

Operator describe
= be equal to
<> Not equal to
> greater than
< less than
>= Greater than or equal to
<= Less than or equal to
BETWEEN In a certain range
LIKE Search for a pattern

 

notes:In some versions of SQL, the operator < > can be written as! =。

 


 

Use of quotation marks

Note that we use single quotation marks around conditional values.

SQL uses single quotation marksText value(most database systems also accept double quotes.). If it isnumerical value, please do not use quotation marks.

 

Text value:

 

This is true:
SELECT * FROM Persons WHERE NAME='USER'

This is wrong:
SELECT * FROM Persons WHERE NAME =USER

 

Value:

This is true:
SELECT * FROM Persons WHERE Year>1965

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