我有2个要合并的sql字符串:
第一个表包含产品的所有数据
第二个表(inner join
)具有具有组价格的产品的所有数据。
但我得到不同的结果
测试搜索“ sku”
SELECT sku
FROM `c3eiwitlive`.`catalog_product_entity`
WHERE (
`entity_id` LIKE '%17086%'
)
group_price
表上的直接sql结果269条记录
SELECT SKU, value
FROM `c3eiwitlive`.`catalog_product_entity_group_price` AS T1
INNER JOIN
`c3eiwitlive`.`catalog_product_entity` AS T2
ON T1.`entity_id` = T2.`entity_id`;
合并的SQL返回较少的记录
结果234条记录
SELECT name
FROM `c3eiwitlive`.`catalog_product_flat_1` AS T1
WHERE T1.`sku`
IN (
SELECT sku
FROM `c3eiwitlive`.`catalog_product_entity_group_price` AS T1
INNER JOIN `c3eiwitlive`.`catalog_product_entity` AS T2 ON T1.`entity_id` = T2.`entity_id`
)
最佳答案
在我看来,'catalog_product_flat_1'表中缺少一些sku条目。
为什么不反转查询以标识丢失的行?
SELECT sku
FROM `c3eiwitlive`.`catalog_product_entity_group_price` AS T1
INNER JOIN `c3eiwitlive`.`catalog_product_entity` AS T2 ON T1.`entity_id` = T2.`entity_id`
WHERE sku
NOT IN (
SELECT sku from `c3eiwitlive`.`catalog_product_flat_1`
)