小编vdo*_*nis的帖子

从表中选择在另一个表中没有行的数据

我有2张桌子。首先"product" (id)。第二- "product_has_option_value" (product_id, option_value_id)

我怎样才能获得id没有一些的产品option_value_id(例如 10)?“product_has_option_value”具有多对多关系。

好的。我想我找到了解决方案:

select p.id 
from product p 
where p.id not in 
  (select distinct(product_id)
   from product_has_option_value 
   where option_value_id=543)
Run Code Online (Sandbox Code Playgroud)

mysql select if-not-exists

2
推荐指数
1
解决办法
91
查看次数

标签 统计

if-not-exists ×1

mysql ×1

select ×1