-1

I have 2 tables tbl_Party and Link_Party

tbl_Party
Columns
PartyId - uniquekey,
PartyNAme,
sk_party,

Link table

link_party
Coulmns
PartyId_a,
PartyId_b,
linktype

Now Party table will have different partyids. Some of the parties from the party table could be linked to each other in the link table Now, I need to wrote a query like

select 
  partyid_a,
  sk_party,
  partyid_b,
  sk_party 
from 
  party, 
  link_party
bobroxsox
  • 902
  • 2
  • 10
  • 26
user2501620
  • 15
  • 1
  • 1
  • 7

2 Answers2

0

If I've understood your table structure correctly then something like the following:

SELECT      L.PartyId_a,
            PA.sk_party,
            L.PartyId_b,
            PB.sk_party
FROM        link_party L
INNER JOIN  tbl_Party PA ON L.PartyId_a = PA.PartyId
INNER JOIN  tbl_Party PB ON L.PartyId_b = PB.PartyId
weenoid
  • 1,156
  • 2
  • 11
  • 24
0

Ref this you will get some idea

SELECT
  a.partyid    AS partyid_a,
  a.sk_party     AS sk_party_a, 
  b.partyid    AS partyid_b,
  b.sk_party     AS sk_party_b, 
FROM
  party              AS a
INNER JOIN
  link_party            AS lp
    ON lp.partyid_a = a.partyid
INNER JOIN
  party              AS b
  ON lp.partyid_b = b.partyid
Community
  • 1
  • 1
Salil
  • 46,566
  • 21
  • 122
  • 156