mysql or用法是什么

 2022-07-22    554  

mysql or用法是什么

MySQL中or语句用法示例

mysql or用法是什么

1.mysql中or语法的使用,在mysql语法中or使用注意点。 项目遇到坑,遍历发放奖励数据查询错误!!!

$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
      ;

sql中的or语法一般用于多个条件的查询,上面的语法查询的相当于:两个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;

2. 要想查询act_type = 4 and user_id = 11123 或者等于 p.`act_type` = 5 and user_id = 11123的数据集合 or两边的条件一定要加()。

$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
      ;


  •  标签:  
  • mysql
  •  

原文链接:https://77isp.com/post/2199.html

=========================================

https://77isp.com/ 为 “云服务器技术网” 唯一官方服务平台,请勿相信其他任何渠道。