Examples of using the or statement in MySQL

Examples of using the or statement in MySQL

1. The use of or syntax in MySQL, and the points to note when using or in MySQL syntax. The project encountered a pitfall, and there was an error in querying the reward data! ! !

$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: the data sets obtained by two sql queries.

 $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. To query the data set where act_type = 4 and user_id = 11123 or p.`act_type` = 5 and user_id = 11123, you must add () to the conditions on both sides of the 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
      ;

Summarize

The above is all the content of this article about the usage examples of or statements in MySQL. I hope it will be helpful to you. Interested friends can continue to refer to this site: Introduction to MySQL statement comment method, Analysis of SQL and MySQL statement execution order, Examples of optimization techniques for slow subquery efficiency of MySQL in statement, etc. If you have any questions, you can leave a message at any time and the editor will reply to you in time. Thank you friends for your support of 123WORDPRESS.COM!

You may also be interested in:
  • How to handle the failure of inserting rare characters in MySQL (Incorrect string value)
  • Solve the problem of Access denied for user ''root''@''%'' to database ''xxx'' after creating a database in MySQL
  • Solution to ERROR 1366 when entering Chinese in MySQL
  • Solution to MySQLSyntaxErrorException when connecting to MySQL using bitronix
  • Comparison of MySQL and Oracle SQL Language Differences

<<:  Installing Win10 system on VMware workstation 14 pro

>>:  Vue implements an example of pulling down and scrolling to load data

Recommend

Vue implements the full selection function

This article example shares the specific code of ...

Detailed explanation of the EXPLAIN command and its usage in MySQL

1. Scenario description: My colleague taught me h...

MySql knowledge points: transaction, index, lock principle and usage analysis

This article uses examples to explain the princip...

Vue3+TypeScript implements a complete example of a recursive menu component

Table of contents Preface need accomplish First R...

Sample code for implementing multi-application deployment using tomcat+nginx

Table of contents Multi-application deployment 1-...

Implementing WeChat tap animation effect based on CSS3 animation attribute

Seeing the recent popular WeChat tap function, I ...

HTML blockquote tag usage and beautification

Blockquote Definition and Usage The <blockquot...

The use and difference between vue3 watch and watchEffect

1.watch listener Introducing watch import { ref, ...

avue-crud implementation example of multi-level complex dynamic header

Table of contents Preface Background data splicin...

Simple implementation of mini-vue rendering

Table of contents Preface Target first step: Step...

Detailed explanation of how to use eslint in vue

Table of contents 1. Description 2. Download rela...

Best way to replace the key in json object

JSON (JavaScript Object Notation, JS Object Notat...

Tutorial on installing and configuring MySql5.7 in Alibaba Cloud ECS centos6.8

The default MySQL version under the Alibaba Cloud...