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 mysql conditions to query and and or and their priority

2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

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

Editor this time to share with you how to use mysql conditions to query and and or and their priority, the article is rich, interested friends can learn about it, I hope you can get something after reading this article.

Introduction of mysql and and or

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

When using the OR keyword:

As long as one of these query conditions is met, such records will be queried. If any of these query conditions are not met, such records will be excluded.

When using the and keyword:

All conditions need to be met and such records will be queried. If any of the conditions are not met, such records will be excluded. Mysql and and or instance

The table data to be used in this example is as follows:

Titlecontentcategoryseo_namephp Array php Array using Analysis 1phpmysql distinctmysql distinct instance 2mysqljava arrayjava array usage method 3javaphp inputphp input how to get the value 4php

(1) AND conditional query operator example:

Use AND to display all data with a title of "php array" and a category of 1:

SELECT * FROM ar WHERE title='php array 'AND category='1'

Results:

Titlecontentcategoryseo_namephp array php array using parse 1php

(2) OR conditional operator example

Use OR to display all data whose title is "java array" or seo_name is "php":

SELECT * FROM ar WHERE title='java array' OR seo_name='php'

Results:

The titlecontentcategoryseo_namephp array php array uses the analysis 1phpjava arrayjava array usage method 3javaphp inputphp input to get the value 4php

(3) combine AND and OR operators

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

SELECT * FROM ar WHERE (title='java array' OR category='4') AND seo_name='php'

Results:

How to get 4phpand and or priority for titlecontentcategoryseo_namephp inputphp input

You can include any number of and and or operators in where, and when there are no other symbols, such as parentheses, SQL executes the and condition first, followed by the or statement, such as:

Select * from table from id=1 or id=2 and price > = 10 pm * http://www.manongjc.com/article/1439.html * /

By default, this statement executes id=2 with price greater than or equal to 10, or id=1.

If you add parentheses:

Select * from table from (id=1 or id=2) and price > = 10

Then the statement executes id=1 or id=2, and the price is greater than or equal to 10.

After reading this article on how to use mysql conditions to query and and or and their priorities, if you think the article is well written, you can share it with more people.

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

Database

Wechat

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

12
Report