dougu5886 2012-04-11 15:25
浏览 73

PHP mysql子查询过滤

I have a table like this:

id     price    condition     username
----------------------------------------
 1       20     New           Kim 
 2       30     Used          Kim
 3       40     Used          George
 4       60     New           Tom

My question is about subselection. when I use this query,

SELECT *
FROM `table`
WHERE `username` = 'kim'
  AND `price` = '20'
   OR `condition` = 'New' 

it becomes true for the last condition and brings 2 records where condition = 'New'

However, when I use AND, it returns the correct record.

SELECT *
FROM `table`
WHERE `username` = 'kim'
  AND `price` = '20'
  AND `condition` = 'New'

I want to nest the query such that I can select price and condition only from the results of the first query, which is username. Thanks

  • 写回答

2条回答 默认 最新

  • doumao8355 2012-04-11 15:28
    关注
    SELECT * FROM table WHERE username = 'kim' AND (price = '20' OR condition = 'New');
    
    评论

报告相同问题?

悬赏问题

  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置