How to concatenate multiple rows in Access involving a Link?

前端 未结 2 831
梦毁少年i
梦毁少年i 2021-01-28 23:16

I have the following problem concerning my Access Database:

I have 3 tables which are tblComponents, tblErrors, and linkComponentsErrors. This is a many to many relations

2条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-29 00:03

    You can use my DJoin function for this:

    SELECT 
        tblComponents.compname, 
        DJoin(
            "errname",
            "SELECT compID, errname 
                FROM linkComponentsErrors 
                INNER JOIN tblErrors ON linkComponentsErrors.errID = tblErrors.errID",
            "compID = " & [tblComponents].[compID] & "",
            ", ") AS errnames
    FROM 
        tblComponents 
    INNER JOIN 
        linkComponentsErrors ON tblComponents.compID = linkComponentsErrors.compID
    GROUP BY 
        tblComponents.compname, 
        DJoin(
            "errname",
            "SELECT compID, errname 
                FROM linkComponentsErrors 
                INNER JOIN tblErrors ON linkComponentsErrors.errID = tblErrors.errID",
            "compID = " & [tblComponents].[compID] & "",
            ", "), 
        tblComponents.compID
    ORDER BY 
        tblComponents.compID;
    

    Output:

提交回复
热议问题