这是一个运行速度非常慢的 MS Access 查询。该Results
表是主表P
,B
、S
和C
表是子表。列组合在所有这些表中都是唯一的Index
。因此,例如,表中ResultID
只能有一行是“1”和2。我没有使用 JOIN,因为 MS Access 仅支持内部联接,而我需要的是外部联接,因为我想显示表中的所有记录,即使在任何其他表中都没有相应的记录。C
Index
ResultID
Results
SELECT
[Results].[Id],
[Results].[Name],
[Results].[OfferPrice],
[Results].[RegPrice],
[Results].[ImageFileName],
[Results].[Image],
[Results].[URL],
(SELECT P.P FROM P WHERE P.ResultID = Results.Id AND P.Index = "0") as P0,
(SELECT P.P FROM P WHERE P.ResultID = Results.Id AND P.Index = "1") as P1,
(SELECT P.P FROM P WHERE P.ResultID = Results.Id AND P.Index = "2") as P2,
(SELECT P.P FROM P WHERE P.ResultID = Results.Id AND P.Index = "3") as P3,
(SELECT P.P FROM P WHERE P.ResultID = Results.Id AND P.Index = "4") as P4,
(SELECT P.P FROM P WHERE P.ResultID = Results.Id AND P.Index = "5") as P5,
(SELECT B.B FROM B WHERE B.ResultID = Results.Id AND B.Index = "0") as B0,
(SELECT B.B FROM B WHERE B.ResultID = Results.Id AND B.Index = "1") as B1,
(SELECT B.B FROM B WHERE B.ResultID = Results.Id AND B.Index = "2") as B2,
(SELECT B.B FROM B WHERE B.ResultID = Results.Id AND B.Index = "3") as B3,
(SELECT B.B FROM B WHERE B.ResultID = Results.Id AND B.Index = "4") as B4,
(SELECT B.B FROM B WHERE B.ResultID = Results.Id AND B.Index = "5") as B5,
(SELECT B.B FROM B WHERE B.ResultID = Results.Id AND B.Index = "6") as B6,
(SELECT B.B FROM B WHERE B.ResultID = Results.Id AND B.Index = "7") as B7,
(SELECT B.B FROM B WHERE B.ResultID = Results.Id AND B.Index = "8") as B8,
(SELECT B.B FROM B WHERE B.ResultID = Results.Id AND B.Index = "9") as B9,
(SELECT B.B FROM B WHERE B.ResultID = Results.Id AND B.Index = "10") as B10,
(SELECT B.B FROM B WHERE B.ResultID = Results.Id AND B.Index = "11") as B11,
(SELECT B.B FROM B WHERE B.ResultID = Results.Id AND B.Index = "12") as B12,
(SELECT B.B FROM B WHERE B.ResultID = Results.Id AND B.Index = "13") as B13,
(SELECT B.B FROM B WHERE B.ResultID = Results.Id AND B.Index = "14") as B14,
(SELECT B.B FROM B WHERE B.ResultID = Results.Id AND B.Index = "15") as B15,
(SELECT B.B FROM B WHERE B.ResultID = Results.Id AND B.Index = "16") as B16,
(SELECT S.S FROM S WHERE S.ResultID = Results.Id AND S.Index = "1") as S1,
(SELECT S.S FROM S WHERE S.ResultID = Results.Id AND S.Index = "2") as S2,
(SELECT S.S FROM S WHERE S.ResultID = Results.Id AND S.Index = "3") as S3,
(SELECT S.S FROM S WHERE S.ResultID = Results.Id AND S.Index = "4") as S4,
(SELECT S.S FROM S WHERE S.ResultID = Results.Id AND S.Index = "5") as S5,
(SELECT S.S FROM S WHERE S.ResultID = Results.Id AND S.Index = "6") as S6,
(SELECT S.S FROM S WHERE S.ResultID = Results.Id AND S.Index = "7") as S7,
(SELECT S.S FROM S WHERE S.ResultID = Results.Id AND S.Index = "8") as S8,
(SELECT S.S FROM S WHERE S.ResultID = Results.Id AND S.Index = "9") as S9,
(SELECT S.S FROM S WHERE S.ResultID = Results.Id AND S.Index = "10") as S10,
(SELECT C.C FROM C WHERE C.ResultID = Results.Id AND C.Index = "0") as C0,
(SELECT C.C FROM C WHERE C.ResultID = Results.Id AND C.Index = "1") as C1,
(SELECT C.C FROM C WHERE C.ResultID = Results.Id AND C.Index = "2") as C2,
(SELECT C.C FROM C WHERE C.ResultID = Results.Id AND C.Index = "3") as C3,
(SELECT C.C FROM C WHERE C.ResultID = Results.Id AND C.Index = "4") as C4,
(SELECT C.C FROM C WHERE C.ResultID = Results.Id AND C.Index = "5") as C5,
(SELECT C.C FROM C WHERE C.ResultID = Results.Id AND C.Index = "6") as C6,
(SELECT C.C FROM C WHERE C.ResultID = Results.Id AND C.Index = "7") as C7,
(SELECT C.C FROM C WHERE C.ResultID = Results.Id AND C.Index = "8") as C8,
(SELECT C.C FROM C WHERE C.ResultID = Results.Id AND C.Index = "9") as C9,
(SELECT C.C FROM C WHERE C.ResultID = Results.Id AND C.Index = "10") as C10
FROM
Results