Access 2007中的Group By / Distinct

时间:2014-04-23 17:17:01

标签: group-by ms-access-2007 distinct

我有一个查询,我在其中选择多个列,但只需要结果返回一组不同的数据:

Dim strSQL As String

strSQL = "SELECT REQUIRED_TOOLS.REQUIRED_TOOL_NSN, REQUIRED_TOOLS.REQUIRED_TOOL_NAME, REQUIRED_TOOLS.ID, OEM_MASTER.OEM_No, REQUIRED_TOOLS.IS_TEST_EQUIP, OEM_MASTER.OEM_IN_INVENTORY, AIRCRAFT_EQUIPMENT.ID"

strSQL = strSQL & " FROM (OEM_MASTER INNER JOIN (REQUIRED_TOOLS INNER JOIN REL_OEM_TO_NSN ON REQUIRED_TOOLS.ID = REL_OEM_TO_NSN.NSN_REF_ID) ON OEM_MASTER.ID = REL_OEM_TO_NSN.OEM_REF_ID) INNER JOIN (AIRCRAFT_EQUIPMENT INNER JOIN REL_AC_EQUIP_TO_TOOLS ON AIRCRAFT_EQUIPMENT.ID = REL_AC_EQUIP_TO_TOOLS.AC_EQUIP_ID) ON REQUIRED_TOOLS.ID = REL_AC_EQUIP_TO_TOOLS.TOOL_ID"

strSQL = strSQL & " WHERE (((REQUIRED_TOOLS.IS_TEST_EQUIP)=No) AND ((OEM_MASTER.OEM_IN_INVENTORY)=Yes) AND ((AIRCRAFT_EQUIPMENT.ID)=" & Me.List0.Column(2) & "))"

strSQL = strSQL & " GROUP BY REQUIRED_TOOLS.REQUIRED_TOOL_NAME"

Me.List1.RowSource = strSQ

当我注释掉group by子句时,我得到了结果,但REQUIRED_TOOL_NAME的结果多了(它只存在于自己的表中一次,但在OEM_MASTER.OEM_No表/列中可以有多个OEM_MASTER.OEM_No引用)。我需要过滤掉列表中的所有重复实例。

感谢。

0 个答案:

没有答案