加入SQL Server [英] Join in sql server
问题描述
嗨
我有3张桌子.
表1
StreamID int,
流Varchar,
表2
PostStreamID int,
流Varchar,
表3
UserID int
StreamID varchar(10),
PostStreamID varchar(10),
userName char(10)
表1
-------------------------------------------
StreamID流
1个MCA
2 M.Tech
3 B.Tech
表2
-------------------------------------------
PostStreamID流
1 MA
2 Msc
3 Bsc
表3
--------------------------------------
UserID StreamID PostStreamID userName
1''1'',''2''``1'',''3''Jhon
2''2'',''3''''2'',''3''Sachin
现在我想加入所有3个表并获取Stream和用户名.我该怎么做?请帮助我.
Hi
I have 3 table.
Table1
StreamID int,
Stream Varchar,
Table2
PostStreamID int,
Stream Varchar,
Table3
UserID int
StreamID varchar(10),
PostStreamID varchar(10),
userName char(10)
Table1
-------------------------------------------
StreamID Stream
1 MCA
2 M.Tech
3 B.Tech
Table 2
-------------------------------------------
PostStreamID Stream
1 MA
2 Msc
3 Bsc
Table3
--------------------------------------
UserID StreamID PostStreamID userName
1 ''1'',''2'' ''1'',''3'' Jhon
2 ''2'',''3'' ''2'',''3'' Sachin
Now i want to join all the 3 table and fetch Stream and user name.How Can i do this? Please Help me.
推荐答案
表结构未规范化.首先,您需要对表格进行规范化,因为它们甚至不属于1st Normal形式.
然后正确输入数据.然后,只有您才能设置表之间的关系并通过联接轻松获取数据.
您现在拥有的表结构是凌乱的,根本不适合按照我的方式联接(非关系).
The table structure is not normalized. You first need to normalize your tables as they dont even fall in 1st Normal form.
Then enter data correctly. Then only you will be able to set relationship between tables and fetch data easily with joins.
The table structure you have right now is messy and not at all fit for joining (un-relational) the way I see it.
这篇关于加入SQL Server的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!