MySQL需要连接Grocery Stores,UPC代码和价格表

时间:2011-04-20 19:52:21

标签: mysql sql join

我正在跟踪连锁商店的杂货价格,我在使用MySQL声明时遇到了麻烦。

我的三个表格设置如下:

  1. upccode_table,包含两个字段:upc_code,item_name

  2. storelist_table,包含三个字段:store_code,store_name,store_address

  3. price_table,包含四个字段:upc_code,store_code,price_amount,price_date

  4. 我需要我的price_table来显示/返回所有可能的组合!!这包括所有UPC代码,所有商店名称和所有price_amounts,即使IF NULL。

    我的数据输入将用真实值替换NULL值。

    我的第一次尝试,但我的语法不正确。

    select itemlist.upccode as Code, storetable.storecode as Number   
    from code itemlist  
    inner join Pricelist p on itemlist.upccode = pricelist.upccode  
    inner join storenumber s on storetable.storenumber = pricelist.storenumber  
    order by itemlist.upccode  
    

1 个答案:

答案 0 :(得分:1)

将您的INNER联接更改为LEFT OUTER join:

select itemlist.upccode as Code, storetable.storecode as Number
from code itemlist
LEFT OUTER join Pricelist p on itemlist.upccode = pricelist.upccode
LEFT OUTER join storenumber s on storetable.storenumber = pricelist.storenumber
order by itemlist.upccode