0

I have the following tables and relationships:

T1 -> id1, v1, v2
T2 -> id2, va, vb, vc
T3 -> id1, id2, v

T1 0-to-many T3
T2 0-to-many T3

I want to select v1, v2, va, vb, vc, v where id1 & id2 exist in T3.
What SQL-query will give this result?

4

3 回答 3

3

试试这个——

SELECT 
      t1.v1
    , t1.v2
    , t2.va
    , t2.vb
    , t2.vc
FROM dbo.T3 t3
JOIN dbo.T2 t2 ON t2.id2 = t3.id2
JOIN dbo.T1 t1 ON t1.id2 = t3.id2
于 2013-05-17T08:54:39.537 回答
2

您需要的是 a ,INNER JOIN因为您只想要s 在or上T3存在的记录。IDT1T2

SELECT  v1, v2, va, vb, vc, v
FROM    T3 INNER JOIN T1 ON T3.id1 = T1.id1
        INNER JOIN T2 ON T3.ID2 = T2.id2

要进一步了解有关联接的更多信息,请访问以下链接:

于 2013-05-17T08:54:53.337 回答
1
select t1.v1, t1.v2, t2.va, t2.vb, t2.vc, t3.v from T1 t1, T2 t2, T3 t3 where t1.id1=t3.id1 and t3.id2=t2.id2
于 2013-05-17T08:54:46.893 回答