当前位置:Gxlcms > mysql > sql中or语法介绍

sql中or语法介绍

时间:2021-07-01 10:21:17 帮助过:96人阅读

1.mysql中or语法的使用,在mysql语法中or使用注意点。


  1. $sql = 'SELECT
  2. *
  3. FROM
  4. `vvt_spread_doubleegg_exchange_award` AS p
  5. WHERE
  6. p.`act_type` = 4 or p.`act_type` = 5
  7. AND
  8. p.`user_id` = ' .$user_id
  9. ;

sql中的or语法一般用于多个条件的查询,上面的语法查询的相当于:两个sql查询出来的数据集合。


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

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


  1. $sql = 'SELECT
  2. *
  3. FROM
  4. `vvt_spread_doubleegg_exchange_award` AS p
  5. WHERE
  6. (p.`act_type` = 4 or p.`act_type` = 5)
  7. AND
  8. p.`user_id` = ' .$user_id
  9. ;

以上就是sql中or语法介绍的详细内容,更多请关注Gxl网其它相关文章!

人气教程排行