Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use AND operator and OR operator in SQL statement

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

Xiaobian to share with you how to use the AND operator and OR operator in the SQL sentence. I hope you will get something after reading this article. Let's discuss it together.

SQL AND & OR operator

The AND and OR operators are used to filter records based on more than one condition.

AND and OR can combine two or more conditions in the WHERE clause.

If both the first and second conditions are true, the AND operator displays a record.

If only one of the first and second conditions is true, the OR operator displays a record.

"Persons" table:

LastName FirstName Address CityAdams John Oxford Street LondonBush George Fifth Avenue New YorkCarter Thomas Changan Street BeijingCarter William Xuanwumen 10 Beijing

AND operator instance

Use AND to display all people with the last name "Carter" and the first name "Thomas":

SELECT * FROM Persons WHERE FirstName= "Thomas" AND LastName= "Carter"

Results:

LastName FirstName Address CityCarter Thomas Changan Street Beijing

OR operator instance

Use OR to display all people with the last name "Carter" or "Thomas":

SELECT * FROM Persons WHERE firstname= "Thomas" OR lastname= "Carter"

Results:

LastName FirstName Address CityCarter Thomas Changan Street BeijingCarter William Xuanwumen 10 Beijing

Combine AND and OR operators

We can also combine AND and OR (using parentheses to form complex expressions):

SELECT * FROM Persons WHERE (FirstName= "Thomas" OR FirstName= "William") AND LastName= "Carter"

Results:

After reading this article, LastName FirstName Address CityCarter Thomas Changan Street BeijingCarter William Xuanwumen 10 Beijing, I believe you have some understanding of "how to use AND operator and OR operator in SQL sentence". If you want to know more about it, please follow the industry information channel. Thank you for reading!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report