Home > Database > Mysql Tutorial > body text

Example of usage of or statement in MySQL

小云云
Release: 2017-12-08 11:20:59
Original
2599 people have browsed it

1. The use of or syntax in mysql, points to note when using or in mysql syntax. The project encountered a pitfall and there was an error in querying the reward data while traversing it. This article mainly introduces the usage examples of the or statement in MySQL. The editor thinks it is quite good, so I share it with you here for the reference of friends who need it.


$sql = 'SELECT 
        * 
      FROM 
        `vvt_spread_doubleegg_exchange_award` AS p
      WHERE
        p.`act_type` = 4 or p.`act_type` = 5
      AND
        p.`user_id` = ' .$user_id
      ;
Copy after login


The or syntax in sql is generally used for queries with multiple conditions. The above syntax query is equivalent to: Two data sets queried by SQL.


 $sql = 'SELECT * FROM `vvt_spread_doubleegg_exchange_award` AS p WHERE p.`act_type` = 4;
 $sql = 'SELECT * FROM `vvt_spread_doubleegg_exchange_award` AS p WHERE p.`act_type` = 5 AND p.`user_id` = ' .$user_id;
Copy after login


2. To query act_type = 4 and user_id = 11123 or equal to p.`act_type` = 5 and User_id = 11123 data set or conditions on both sides must be added ().


$sql = 'SELECT 
        * 
      FROM 
        `vvt_spread_doubleegg_exchange_award` AS p
      WHERE
        (p.`act_type` = 4 or p.`act_type` = 5)
      AND
        p.`user_id` = ' .$user_id
      ;
Copy after login

Have you learned it after reading the above examples? Hurry up and give it a try.

Related recommendations:

Introduction to the difference between php foreach and for statement usage_PHP tutorial

jQuery uses each method and for statement to traverse arrays Example

Character order of order by in in mysql (recommended)

The above is the detailed content of Example of usage of or statement in MySQL. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!