Home  >  Article  >  Database  >  Introduction to or syntax in sql

Introduction to or syntax in sql

一个新手
一个新手Original
2017-10-17 10:12:063390browse

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
            ;

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>

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
            ;

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!

Statement:
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