是否可以用INNER JOIN
s 编写此查询?
SELECT links.product_id AS entity_id, products.sku, links.`linked_product_id` AS linked_entity_id, products2.`sku` AS linked_skus
FROM catalog_product_entity AS products,
catalog_product_link AS links,
catalog_product_entity AS products2
WHERE links.`product_id` = products.`entity_id`
AND links.`linked_product_id` = products2.`entity_id`
另外,catalog_product_link
有一个 column type_id
,我想只获得最后带有条件的type_id
值的行,但它不起作用。我该如何去只获取记录?1
AND catalog_product_link.type_id = 1
type_id=1
我遇到了一个问题,当我添加WHERE links.type_id=1
到语句中时,结果是错误的。下面的所有product_id
内容都是相同的数字(相同的 entity_id/product_id),并且下面的所有内容sku
都是 NULL。linked_product_id
并且linked_skus
是正确的。
更多信息:
catalog_product_entity
| entity_id | sku | ... |
-------------------
| 1 | abc | |
| 2 | qwe | |
| 3 | yui | |
catalog_product_link
| product_id (same as entity_id) | linked_product_id | type_id |
----------------------------------------------------------------
| 1 | 5 | 1 |
| 1 | 6 | 1 |
| 2 | 1 | 2 |
| 3 | 1 | 1 |
| 3 | 2 | 1 |
| 3 | 4 | 1 |