连接 2 个表一个值
joining 2 tables one value
我有 2 个 table:
table 1 = 关系所以列 parent_id 和列 child_id 和
table 2是entity_id和货号。(entity_id=父子是)
我想 join/select/union 他们这样我得到的结果不是 de parent_id 和 child_id 我在 2 列中得到父文章编号和子文章编号
我有点烂,你们能帮帮我吗?
catalog_product_entity
Entity ID SKU
34445 10199
59301 10199001001
catalog_product_super_link
product_id parent_id
59301 34445
我想要的结果
parent sku child sku
10199 10199001001
这听起来像是第二个 table 的两个联接:一个获取父级,另一个获取子级:
select ap.article_number parent_article_number, ac.article_number child_article_number
from relations r
inner join articles ap on ap.entity_id = r.parent_id
inner join articles ac on ac.entity_id = r.child_id
编辑:这回答了 table 名称和列更改后的问题:
select ep.sku parent_sku, ec.sku child_sku
from catalog_product_super_link l
inner join catalog_product_entity ep on ep.entity_id = l.parent_id
inner join catalog_product_entity ec on ec.entity_id = l.product_id
我有 2 个 table:
table 1 = 关系所以列 parent_id 和列 child_id 和
table 2是entity_id和货号。(entity_id=父子是)
我想 join/select/union 他们这样我得到的结果不是 de parent_id 和 child_id 我在 2 列中得到父文章编号和子文章编号
我有点烂,你们能帮帮我吗?
catalog_product_entity
Entity ID SKU
34445 10199
59301 10199001001
catalog_product_super_link
product_id parent_id
59301 34445
我想要的结果
parent sku child sku
10199 10199001001
这听起来像是第二个 table 的两个联接:一个获取父级,另一个获取子级:
select ap.article_number parent_article_number, ac.article_number child_article_number
from relations r
inner join articles ap on ap.entity_id = r.parent_id
inner join articles ac on ac.entity_id = r.child_id
编辑:这回答了 table 名称和列更改后的问题:
select ep.sku parent_sku, ec.sku child_sku
from catalog_product_super_link l
inner join catalog_product_entity ep on ep.entity_id = l.parent_id
inner join catalog_product_entity ec on ec.entity_id = l.product_id