MySQL or statement usage example, mysqlor statement example

Source: Internet
Author: User

MySQL or statement usage example, mysqlor statement example

1. Usage of or syntax in mysql. Note the usage of or in mysql syntax. An error occurred while 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 preceding syntax query is equivalent to the data set queried by two SQL statements.

 $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 data sets with act_type = 4 and user_id = 11123 or equal to p. 'Act _ type' = 5 and user_id = 11123 or both conditions, add ().

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

Summary

The above is all the content about the or statement usage examples in MySQL. I hope it will be helpful to you. If you are interested, you can continue to refer to this site: MySQL statement annotation Method Introduction, SQL and MySQL statement execution sequence analysis, and mysql in statement subquery efficiency optimization tips, if you have any questions, you can leave a message at any time. The editor will reply to you in a timely manner. Thank you for your support for the website!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.