当前位置: 首页 > 网络学院 > 服务端脚本教程 > SQL > SQL 与 & OR
AND and OR join two or more conditions in a WHERE clause.
AND 和 OR 可以在WHERE子句中将两个过多个条件结合起来
The AND operator displays a row if ALL conditions listed are true. The OR operator displays a row if ANY of the conditions listed are true.
当WHERE字句使用AND操作,那么得让AND所关联的所有条件都为真才会将结果显示出来。 使用OR则只需要其中的一个条件符合就可以将该结果显示出来
LastName | FirstName | Address | City |
---|---|---|---|
Hansen | Ola | Timoteivn 10 | Sandnes |
Svendson | Tove | Borgvn 23 | Sandnes |
Svendson | Stephen | Kaivn 18 | Sandnes |
Use AND to display each person with the first name equal to "Tove", and the last name equal to "Svendson":
这句使用了AND,数据要显示那么它的first name必须为"Tove"而且last name必须为"Svendson"。
SELECT * FROM Persons |
结果:
LastName | FirstName | Address | City |
---|---|---|---|
Svendson | Tove | Borgvn 23 | Sandnes |
Use OR to display each person with the first name equal to "Tove", or the last name equal to "Svendson":
这句使用了OR,数据要显示的话那么它所包含的数据里first name为"Tove"或者last name为"Svendon" :
SELECT * FROM Persons |
结果:
LastName | FirstName | Address | City |
---|---|---|---|
Svendson | Tove | Borgvn 23 | Sandnes |
Svendson | Stephen | Kaivn 18 | Sandnes |
You can also combine AND and OR (use parentheses to form complex expressions):
你还可以将AND 与 OR 混合起来使用
SELECT * FROM Persons WHERE |
结果:
LastName | FirstName | Address | City |
---|---|---|---|
Svendson | Tove | Borgvn 23 | Sandnes |
Svendson | Stephen | Kaivn 18 | Sandnes |