basic many-to-many sql select query

后端 未结 9 1929
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-17 03:06

I think this should be easy, but it\'s evading me. I\'ve got a many-to-many relationship between Accounts and Account Groups. An Account can be in zero or more Groups, so I\

9条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-17 03:51

    This

    SELECT a.BankName, a.AcctNumber, a.Balance, ag.GroupName
    FROM (Accounts a 
          LEFT JOIN JoinAccountsGroups jag 
          ON a.ID = jag.AID) 
          LEFT JOIN AccountGroups ag
          ON jag.GID = ag.GroupName;
    

    Will select the data for the first table, however to concatenate the groups (Monthly, Payroll), you would need a User Defined Function (UDF), wich would not be available to Jet, so processing in PHP would be necessary.

    You may wish to read Understanding SQL Joins. It refers to MySQL but applies to Jet, for the most part.

提交回复
热议问题