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 |
pyu.agrawal
Starting Member
29 Posts |
Posted - 2009-04-03 : 09:07:44
|
I have got tables.Table 1: PartiesPartyID | PartyName | Email Table 2: InwardsInward ID | IDate | FromID | ToID | .... My requirement is that I need a list that would display the output asInwardID | IDate | FromParty | ToParty | ... How do I use get the PartyName from PartyName, in the two columns namely FromParty, and ToPartyUsing Inner Join would fill in either of FromParty, or ToParty.ThanksPeeyush Agrawal |
|
pyu.agrawal
Starting Member
29 Posts |
Posted - 2009-04-03 : 09:14:43
|
I have got tables.Table 1: Parties PartyID | PartyName | Email Table 2: Inwards Inward ID | IDate | FromID | ToID | .... My requirement is that I need a list that would display the output as InwardID | IDate | FromParty | ToParty | ... How do I use get the PartyName from Parties, in the two columns namely FromParty, and ToPartyUsing Inner Join would fill in either of FromParty, or ToParty.ThanksPeeyush Agrawal |
|
|
Wozer
Starting Member
29 Posts |
Posted - 2009-04-03 : 09:17:57
|
Do you have a Common field in both tables that you could inner join on? For example if you had a column for PartyID in the Inwards Table, you could do something like the followingSELECT InwardID, IDate, FromParty, ToParty --Whatever else you needFROM InwardsINNER JOIN Parties ON Inwards.PartyID = Parties.PartyIDIf you don't have a common Column on each table, you cant join them. |
|
|
Ifor
Aged Yak Warrior
700 Posts |
Posted - 2009-04-03 : 09:55:27
|
[code]SELECT I.InwardID, I.IDate, PF.PartyName AS FromParty, PT.PartyName AS ToPartyFROM Inwards I JOIN Parties PF ON I.FromID = PF.PartyID JOIN Parties PT ON I.ToID = PT.PartyID[/code] |
|
|
maeenul
Starting Member
20 Posts |
Posted - 2009-04-04 : 05:42:35
|
yes, Ifor's post is the way of doing this. If you have two columns that is the referring to one column in a table, then you have to join twice.-----------------------maeenulhttp://www.programmingsolution.nethttp://sqlservertipsntricks.blogspot.com |
|
|
pyu.agrawal
Starting Member
29 Posts |
Posted - 2009-04-14 : 12:49:03
|
Thanks iFor,Your script worked :) |
|
|
|
|
|
|
|