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 |
|
ultraman
Starting Member
18 Posts |
Posted - 2004-12-13 : 12:18:11
|
| Hi all !This one is a "newbie" one I'd say. I have one master table with a "BatchNo" field that is linked to 2 child tables by this same field. So for a single BatchNo, you can have different records in both child tables. I would like to get the list of all records for both table for a given BatchNo.Exemple : MasterTable.BatchNo = 'BN04071'ChildTable1BatchNo|JobNoBN04071|01BN04071|02ChildTable2BatchNo|JobNoBN04071|03BN04071|04ChildTable1 have 2 records with ChildTable1.BatchNo = 'BN04071'ChildTable2 have 144 records with ChildTable2.BatchNo = 'BN04071'I want a list of al the 146 records. I tried a simple INNER JOIN query, but I only got a product (288 records)...--------------Ultraman |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2004-12-13 : 12:24:45
|
| select ct.type, mt.BatchNo, ct.JobNofrom MasterTable mtjoin (select type = 'c1', BatchNo, JobNo from ChildTable1 union all select type = 'c2', BatchNo, JobNo from ChildTable2) cton mt.BatchNo = ct.BatchNo orselect type = 'c1', mt.BatchNo, ct.JobNofrom MasterTable mtjoin ChildTable1 cton mt.BatchNo = ct.BatchNo union allselect type = 'c2', mt.BatchNo, ct.JobNofrom MasterTable mtjoin ChildTable2 cton mt.BatchNo = ct.BatchNo ==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
ultraman
Starting Member
18 Posts |
Posted - 2004-12-13 : 13:25:37
|
| That's good ! Thanks a lot !--------------Ultraman |
 |
|
|
|
|
|