1.mysql中or語法的使用,在mysql語法中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 ;
sql中的or語法一般用於多個條件的查詢,上面的語法查詢的相當於:兩個sql查詢出來的資料集合。
<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兩邊的條件一定要加()。
$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 ;
以上是sql中or語法介紹的詳細內容。更多資訊請關注PHP中文網其他相關文章!