mySQL查询多个表

时间:2015-11-10 11:40:16

标签: mysql multiple-tables

请帮助!我需要获取与'42'的cat_id相关的entry_id,然后找到附加到我们刚刚过滤的entry_id的所有cat_id。然后我需要获取cat_id_id的cat_group_id。请参阅下表的屏幕截图:

enter image description here

enter image description here

修改

E.g。 entry_id 92分配了cat_id 42。但它也有48&这是我需要输出的这些数字。但是只有当entry_id在cat_id 42中时

1 个答案:

答案 0 :(得分:1)

我不太了解你想要的是什么,是吗?

select
  group_id
from
  exp_categories
inner join
  exp_category_posts
  on exp_category_posts.cat_id = exp_categories.cat_id
where
  entry_id in (select entry_id from exp_category_posts where cat_id = 42)
;

注意:我没有创建表来测试它,但我认为查询没问题