Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
Fred_Scuttle
Starting Member
13 Posts |
Posted - 2005-11-04 : 03:54:43
|
| Hi I am fairly new to TSQL and am studying for the 70-229 exam.I am trying to create a view which will act as a junction table so that I can run queries on tables that have a many to many relationship.I have Table1 and Table2The link between both is a field called ACCOUNTNOThe Unique Field for my junction table is called RECID (By that I mean that every RECID in tables1 and Table2 is different, whereas the ACCOUNTNO field will appear many times in both tables)Does this make sense? (or only to me?)ANy way I want to create a view that shows metwo columns - RECID and ACCOUNTNO.But shows me the stuff from both tables.EXAMPLERECID ACCOUNTNO1234 10012345 10013456 10024567 10025678 10026789 10037890 10040123 1004ThanksFred |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-11-04 : 04:00:25
|
| Post some sample data from two tables and the result you wantMadhivananFailing to plan is Planning to fail |
 |
|
|
Fred_Scuttle
Starting Member
13 Posts |
Posted - 2005-11-04 : 05:02:25
|
Here is attached image of this requirement |
 |
|
|
Fred_Scuttle
Starting Member
13 Posts |
Posted - 2005-11-04 : 05:07:27
|
| OOPS - I thought it would attach the image.Table1 ACCNO col1 col2 RECID 1001 data data H1231001 data data H1241001 data data H1251005 data data H1261110 data data H1271001 data data H128Table2 ACCNO col1 col2 RECID1001 data data C0011005 data data C0021001 data data C0031001 data data C004Desired Result RECID ACCOUNTNOH123 1001H124 1001H125 1001H126 1005H127 1110H128 1001C001 1001C002 1005C003 1001C004 1001 |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2005-11-04 : 05:09:27
|
| Try thisSelect RECID,ACCNo from Table1Union AllSelect RECID,ACCNo from Table2MadhivananFailing to plan is Planning to fail |
 |
|
|
Fred_Scuttle
Starting Member
13 Posts |
Posted - 2005-11-04 : 06:00:48
|
| Thanks that works. |
 |
|
|
|
|
|