Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 多对多加入_Asp.net_Sql_Sql Server_Sql Server 2012 - Fatal编程技术网

Asp.net 多对多加入

Asp.net 多对多加入,asp.net,sql,sql-server,sql-server-2012,Asp.net,Sql,Sql Server,Sql Server 2012,您好,我目前正在学习sql,我有两个一对多表,但我不知道如何将它们组合成多对多表。我有一张连接桌 表父级 列父和父id 餐桌儿童 列child和childid 表parentchild--(使用childid连接表选择父项) 列parentid和childid 这是我的密码 select parent.name, parentchild.childid from parent join parentchild on parent.parentID = parentchild.parentid

您好,我目前正在学习sql,我有两个一对多表,但我不知道如何将它们组合成多对多表。我有一张连接桌

表父级 列父和父id

餐桌儿童 列child和childid

表parentchild--(使用childid连接表选择父项) 列parentid和childid

这是我的密码

select parent.name, parentchild.childid from parent
join parentchild
on parent.parentID = parentchild.parentid

select child.name, parentchild.parentid from child
join parentchild 
on child.childID = parentchild.childid

解决方案是编写一个查询,将
parent
表连接到
parentchild
表,然后将
parentchild
表连接到
child

select p.name, c.name 
from parent p
join parentchild pc
    on p.parentid = pc.parentid  -- joins parent to parentchild
join child c
    on c.childID = pc.childid  -- joins parentchild to child