Home > Database > Mysql Tutorial > Introduction to or syntax in sql

Introduction to or syntax in sql

一个新手
Release: 2017-10-17 10:12:06
Original
3429 people have browsed it

1. The use of or syntax in mysql, points to note when using or in mysql syntax.


  $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 sql The queried data collection.


<span style="color: #000000">  $sql = &#39;SELECT *  FROM  `vvt_spread_doubleegg_exchange_award` AS p WHERE  p.`act_type` = 4;<br/><span style="color: #000000">$sql = &#39;SELECT * FROM `vvt_spread_doubleegg_exchange_award` AS p WHERE  <span style="color: #000000">p.`act_type` = 5 AND p.`user_id` = &#39; .$user_id</span>;</span></span>
Copy after login

2. If you want to query the data set of act_type = 4 and user_id = 11123 or equal to p.`act_type` = 5 and user_id = 11123 or both sides The condition must be added ().


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

The above is the detailed content of Introduction to or syntax in sql. 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