0

我有来自 5 个表的复杂选择语句,我想避免其中一个表中具有相同字段值的重复行。

SELECT  role_enname
          ,lu_app_operations.operation_enname
          , lu_applications.app_enname
          , lu_app_oper_groups.oper_group_enname 
FROM app_operation_roles
      ,roles
      ,lu_app_operations
       ,lu_applications
        ,lu_app_oper_groups
WHERE app_operation_roles.role_id=roles.role_id
AND app_operation_roles.app_operation_id=lu_app_operations.app_operation_id
AND roles.app_id=lu_applications.app_id
AND lu_app_operations.app_oper_group_id=lu_app_oper_groups.app_oper_group_id
AND app_operation_roles.retired  =0
AND roles.retired                =0 

在此查询中,我不显示基于重复的行lu_app_operations.operation_enname

4

4 回答 4

0

使用 DISTINCT 关键字:

SELECT DISTINCT role_enname, <rest of your query>
于 2013-08-21T05:40:49.697 回答
0

也许你可以使用 Distinct 和 Group by 来获得结果,但请记住,要连接多个表,最好还是使用 JOIN 而不是 AND

SELECT  DISTINCT role_enname
      ,lu_app_operations.operation_enname
      , lu_applications.app_enname
      , lu_app_oper_groups.oper_group_enname 
FROM app_operation_roles
,roles
,lu_app_operations
,lu_applications
,lu_app_oper_groups
WHERE app_operation_roles.role_id=roles.role_id
AND app_operation_roles.app_operation_id=lu_app_operations.app_operation_id
AND roles.app_id=lu_applications.app_id
AND lu_app_operations.app_oper_group_id=lu_app_oper_groups.app_oper_group_id
AND app_operation_roles.retired  =0
AND roles.retired                =0 
GROUP BY role_enname, 
lu_app_operations.operation_enname,
lu_applications.app_enname,
lu_app_oper_groups.oper_group_enname 
于 2013-08-21T06:03:03.207 回答
0

使用 distinct 关键字如下

SELECT  DISTINCT role_enname,lu_app_operations.operation_enname, lu_applications.app_enname,
lu_app_oper_groups.oper_group_enname 
FROM app_operation_roles,roles,lu_app_operations,lu_applications,lu_app_oper_groups
WHERE app_operation_roles.role_id=roles.role_id
AND app_operation_roles.app_operation_id=lu_app_operations.app_operation_id
AND roles.app_id=lu_applications.app_id
AND lu_app_operations.app_oper_group_id=lu_app_oper_groups.app_oper_group_id
AND app_operation_roles.retired  =0 AND roles.retired                =0 
于 2013-08-21T05:51:04.720 回答
0
SELECT  distinct role_enname,lu_app_operations.operation_enname, lu_applications.app_enname,lu_app_oper_groups.oper_group_enname 
FROM app_operation_roles,roles,lu_app_operations,lu_applications,lu_app_oper_groups
WHERE app_operation_roles.role_id=roles.role_id
AND app_operation_roles.app_operation_id=lu_app_operations.app_operation_id
AND roles.app_id=lu_applications.app_id
AND lu_app_operations.app_oper_group_id=lu_app_oper_groups.app_oper_group_id
AND app_operation_roles.retired =0
AND roles.retired =0
于 2013-08-21T06:06:04.487 回答