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

Detailed explanation of application scenarios of filters in Vue

filter is generally used to filter certain values...

Blog Design Web Design Debut

The first web page I designed is as follows: I ha...

Vue implements the frame rate playback of the carousel

This article example shares the specific code of ...

Detailed explanation of common usage methods of weixin-js-sdk in vue

Link: https://qydev.weixin.qq.com/wiki/index.php?...

How to quickly install Nginx in Linux

Table of contents What is nginx 1. Download the r...

Encoding problems and solutions when mysql associates two tables

When Mysql associates two tables, an error messag...

vue+element-ui implements the head navigation bar component

This article shares the specific code of vue+elem...

Markup Language - Image Replacement

Click here to return to the 123WORDPRESS.COM HTML ...

MySQL index usage monitoring skills (worth collecting!)

Overview In a relational database, an index is a ...

Example of using UserMap in IMG

usemap is an attribute of the <img> tag, use...

Solution to 700% CPU usage of Linux process that cannot be killed

Table of contents 1. Problem Discovery 2. View de...

The pitfalls of deploying Angular projects in Nginx

Searching online for methods to deploy Angular pr...

A brief analysis of the use of watchEffect in Vue3

Preface Everyone should be familiar with the watc...

Handtrack.js library for real-time monitoring of hand movements (recommended)

【Introduction】: Handtrack.js is a prototype libra...