MS ACCESS SELECT查询来自许多表的合并列

时间:2017-07-20 06:59:27

标签: sql select ms-access-2010

我有4张桌子:

  1. Main(ID(KEY),A1_ID,A2_ID,A3_ID);
  2. A1(A1_ID(KEY),NameA1);
  3. A2(A2_ID(KEY),NameA2);
  4. A3(A3_ID(KEY),NameA3);
  5. 您需要查询才能获得下表:

    Main.ID, A1.NameA1, A2.NameA2, A3.NameA3 
    where Main.ID for example = 12
    

    提前感谢您的合作

1 个答案:

答案 0 :(得分:0)

您应该使用JOIN来加入这些表。

SELECT Main.ID
    ,A1.NameA1
    ,A2.NameA2
    ,A3.NameA3
FROM Main
INNER JOIN A1 ON Main.A1_ID = A1.A1_ID
INNER JOIN A2 ON Main.A2_ID = A2.A2_ID
INNER JOIN A3 ON Main.A3_ID = A3.A3_ID
WHERE Main.ID = 12