mysql or syntax is generally used for queries with multiple conditions. Its usage syntax is such as "SELECT * FROM WHERE p.`act_type` = 4 or p.`act_type` =...".
#The operating environment of this article: Windows7 system, mysql8, Dell G3.
What is the usage of or in mysql?
Examples of usage of or statement in MySQL
1.Usage of or syntax in mysql , points to note when using or in mysql syntax. The project encountered a pitfall, and there was an error in querying the reward data while traversing it! ! !
$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: two data sets queried by 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. If you want to query the data set of act_type = 4 and user_id = 11123 or equal to p.`act_type` = 5 and user_id = 11123, you must add () to the conditions on both sides.
$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 ;
Recommended learning: "mysql video tutorial"
The above is the detailed content of What is the usage of mysql or. For more information, please follow other related articles on the PHP Chinese website!