我写了一个查询来检索产品变体id和相应的分类术语(词汇目录)。
有
SELECT
field_data_field_products.field_products_product_id AS p1,
taxonomy_term_data.name AS p2
FROM taxonomy_term_data
INNER JOIN field_data_field_catalog
ON taxonomy_term_data.tid = field_data_field_catalog.field_catalog_tid
INNER JOIN field_data_field_products
ON field_data_field_catalog.entity_id = field_data_field_products.entity_id
我的查询(虽然可能没有优化)检索产品变体ID和相应的分类术语。
但我有两级术语层次结构。所以,我得到的术语是2级。我想得到它而不是'term_level_1 / term_level_2'组合。我怎样才能做到这一点?是否可以在一个查询中?
答案 0 :(得分:1)
不确定您想要输出什么,没有表我无法测试它,但这应该为您提供基于代码的东西: -
SELECT
field_data_field_products.field_products_product_id AS p1,
taxonomy_term_data.name AS p2
c.field_products_product_id AS p1,
a.name AS p2
FROM taxonomy_term_data
INNER JOIN field_data_field_catalog
ON taxonomy_term_data.tid = field_data_field_catalog.field_catalog_tid
INNER JOIN field_data_field_products
ON field_data_field_catalog.entity_id = field_data_field_products.entity_id
INNER JOIN taxonomy_term_hierarchy
ON taxonomy_term_data.tid = taxonomy_term_hierarchy.tid
INNER JOIN taxonomy_term_data a
ON a.tid = taxonomy_term_hierarchy.parent
INNER JOIN field_data_field_catalog b
ON taxonomy_term_data.tid = b.field_catalog_tid
INNER JOIN field_data_field_products c
ON b.entity_id = c.entity_id