这是您的桌子:
category_filter_relations
=========================
id | modification_id
和
category_filter_relations_items
===================================================
id | modification_id | category_filter_relation_id
在查询中,您可以:
SELECT cfr.id AS category_filter_relation_id, -- You select the category_filter_relations id
cfr.modification_id, -- You select the modification_id
FROM category_filter_relations cfr -- Both from the table category_filter_relations
WHERE 1
AND cfr.modification_id = '18340300' -- You add a condition on the modification_id
AND category_filter_relation_id -- You add a condition on an id not in the table category_filter_relations
IN (SELECT category_filter_relations_items.category_filter_relation_id
FROM category_filter_relations_items
WHERE category_filter_relations_items.modification_id = '18340300')
您想要的输出是:
id modification_id
23796 18340300
23270 11111111
AND cfr.modification_id = '18340300'
?
modification_id = 11111111
如果你只要求
modification_id = '18340300'
.
所以试试这个:
SELECT cfr.id,
cfr.modification_id,
FROM category_filter_relations cfr
WHERE cfr.modification_id = '18340300'
UNION
SELECT cfri.id,
cfri.modification_id,
FROM category_filter_relations_items cfri
INNER JOIN category_filter_relations cfr ON cfr.id = cfri.category_filter_relation_id
AND cfr.modification_id = '18340300'
category_filter_relations
具有列名
id
(the)
身份证件
属于
modification_id
(the)
修改\u id
属于
类别过滤关系
)因为这个条件,它等于'18340300'。
UNION
现在我们将有专栏
身份证件
身份证件
在桌子上
category_filter_relations_items
还有一列
修改\u id
修改\u id
分类\筛选\关系\项目
哪里
category_filter_relation_id
是
身份证件
在桌子上
类别过滤关系
有哪些
modification_id = 18340300
这是你要找的吗?