doufei2194 2019-03-17 02:13
浏览 58

带有OR和Brackets的MySQL SELECT查询不起作用

Hi I have a MySQL Select query as follow.

SELECT * 
FROM request
WHERE user_id=$user_id 
   OR vendor=$user_id
   OR (status='' AND services IN ( $service_arr )) 
ORDER BY id DESC

But this query is not working as expected. My OR condition is neglected and this query is getting data only when conditions under brackets are true. Meaning its getting only those rows where column name services has one of the items present in $service_arr.

Thanks

  • 写回答

2条回答 默认 最新

  • doupu3635 2019-03-17 02:22
    关注

    This example most probably help you

    SELECT customer_id,first_name, last_name 
    FROM customers 
    WHERE (last_name = 'atiq')
       OR (last_name = 'hamza' AND state = 'attock')
       OR (last_name = 'usman' AND status = 'Active' AND state = 'islamabad');
    
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度