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

Tips on the mixed use of OR and AND in SQL statements

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

Share

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

Today, there is such a demand. If the logger is customer service, he will query that the order is "the customer service" and there is no matching customer service. At first, I thought of spelling or assigned_id is null directly on the sql sentence. After testing, I found that all the other conditions are useless.

In this case, the condition of the first i.server_org_id = 4 is no longer applicable. From this, we can know that the priority of AND is higher than that of OR. First, the previous AND statement is executed, and then the later OR statement is executed, so the data found is not the data I want.

After thinking about it again, we can look up the corresponding assigned_id first, as follows

The only data found in this way are those with an assigned_id of 153.

Final version:

Finally, all the correct data are read out, which shows that the priority of () is higher than that of AND. Execute () first, and then execute AND.

The above is the whole content of this article, I hope it will be helpful to your study, and I also hope that you will support it.

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