合并父表和子表 [英] Merge Parent and Child Tables
问题描述
我有3张桌子即
分类
CatID 01 02 03 04 05 06 07 < br $>
CatName ABCDEFG
产品
ProdID 01 02 03 04 05 06 07
ProdName PQRSTUV
Cat-Prod
CatID 01 02 02 03 05 06
ProdID 01 02 03 04 04 04
每个产品都有多个类别..
所以我想要一个类似第一类的合并表然后是它的产品
ID名称
01 A --A类别
01 P - 全部A分类产品
02 B - B类别
02 Q - 所有B类产品
03 R - 所有B类产品
如果您有任何其他想法,请告诉我
选择 a.CatName,c.ProdName 来自分类ys as a inner join [Cat-产品 as b a.CatID = b.CatID 内部 join 产品 as c b.ProdID = c.ProdID
输出
CatName ProdName
A p
B q
B r
cs
es
FS
I have 3 Tables i.e.
Categorys
CatID 01 02 03 04 05 06 07
CatName A B C D E F G
Products
ProdID 01 02 03 04 05 06 07
ProdName P Q R S T U V
Cat-Prod
CatID 01 02 02 03 05 06
ProdID 01 02 03 04 04 04
Every Product can have multiple categories ..
So I want a merge table like 1st Category and then its products
ID Name
01 A --A Category
01 P -- All A Category Products
02 B --B Category
02 Q -- All B Category Products
03 R -- All B Category Products
Please let me know if you any other ideas
select a.CatName,c.ProdName from Categorys as a inner join [Cat-Prod] as b on a.CatID=b.CatID inner join Products as c on b.ProdID=c.ProdID
Output
CatName ProdName
A p B q B r c s e s f s
这篇关于合并父表和子表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!