2013-10-30 82 views
1

的使用結果,我有2個SQL字符串我想結合:MySQL錯誤:innerjoin到新的查詢

  • 第一個表有一個產品
  • 的所有數據第二個表(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` 
) 

回答

0

它看起來對我來說,有從「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` 
)