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 |
|
maevr
Posting Yak Master
169 Posts |
Posted - 2009-11-12 : 01:28:04
|
| I need help with joining multiple tables.--Lookup table, I want to join the tables below using the--rows in table1.table1table1_id inttable1_col varchartable2 --parent tabletable2_id (pk)table2_col--child table to table2, can contain multiple references --to table2 or none.table3 table3_idfk_table2_id (fk to table2 id)table3_colI want to fetch all rows in table2 match table1If table3 does not have an rows on that table2_id then Example:table11, 'table1_test1'2, 'table1_test2'3, 'table1_test3'table21, 'table2_test1'2, 'table2_test2'3, 'table2_test3'4, 'table2_test4'5, 'table2_test5'table31, 1, 'table3_test1'1, 2, 'table3_test1'Wanted output:table1_idtable1_coltable2_coltable3_idfk_table3_idtable3_colDisplay all rows from table2 matching table1.When rows are missing in table3 when joining against table2, show all rows that match table1.I know I am going to use a outer join betewwn table2 and table3, but I only want to show the is that matches table1.I know my description is very unclear and for that i apologize. |
|
|
krishnarajeesh
Yak Posting Veteran
67 Posts |
Posted - 2009-11-12 : 08:51:32
|
| "fetch all rows in table2 match table1" , am sorry I couldnt see any relation to write a match between these 2 tables. Could you be more clear pls.Thanks,Krishnawww.SQLServer.in |
 |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2009-11-12 : 11:41:06
|
| Well you need to make it clearPlease post the DDL of the actual tables...Do you know how to generate a script?CREATE TABLE <tablename>....Then Post some sample data in DML FormINSERT INTO TABLE1 (Collist)SELECT <data> UNION ALLSELECT <data> UNION ALLetcThen Post what the sample result set should look likeRead the hint link in my sig for more of an explanationThanksBrett8-)Hint: Want your questions answered fast? Follow the direction in this linkhttp://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspxAdd yourself!http://www.frappr.com/sqlteam |
 |
|
|
|
|
|
|
|