我有三张桌子,我需要在它们之间制作CROSS JOIN
以显示产品的ID和名称以及销售它们的商店,以下是现在的示例
TABLE_PRODUCT
ID_PRODUCT | NAME_PRODUCT
1 | Addidas Super Star
2 | Calvin Klein BAG
TABLE_STORE
ID_STORE | NAME_STORE
1 | ThE 98
2 | C&A
TABLE_PROD_STOR
ID_STORE | ID_PROD
1 | 1
2 | 2
我需要以下格式的结果:
ID STORE | STORE | ID PRODUCT | PRODUCT |
1 | ThE 98 | 1 | Addidas Super Star |
2 | C&A | 2 | CALVIN KLEIN HAT |
我最大的问题是,当我执行CROSS JOIN
时,名称会重复两次。解决方案是什么?
答案 0 :(得分:2)
Select
y.ID_STORE ,
y.NAME_STORE store ,
x.ID_PRODUCT,
x.NAME_PRODUCT product
from
TABLE_PRODUCT x inner join
TABLE_STORE y
on x.ID_PRODUCT =y.ID_STORE
inner join TABLE_PROD_STOR z
on x.ID_PRODUCT =z.ID_STORE