Oracle为链接表选择查询

时间:2013-08-02 10:08:59

标签: sql oracle

我有2个表tbl_Party和Link_Party

tbl_Party
Columns
PartyId - uniquekey,
PartyNAme,
sk_party,

链接表

link_party
Coulmns
PartyId_a,
PartyId_b,
linktype

现在派对表将有不同的派对。 聚会表中的一些参与方可以在链接表中相互链接 现在,我需要写一个像

这样的查询
select 
  partyid_a,
  sk_party,
  partyid_b,
  sk_party 
from 
  party, 
  link_party

2 个答案:

答案 0 :(得分:0)

如果我已正确理解您的表格结构,那么类似于以下内容:

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

答案 1 :(得分:0)

参考this你会得到一些想法

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