sql - getting repeated rows -


i not able why getting repeated data below query. although have used distinct.

the query below- please : might problem joins

select distinct(um.username)'user_name'         ,um.firstname + ' ' + um.lastname 'employee name'         ,us.user_name 'user_id'         ,us.ms_rit_reporting_group_mst_key         ,rg.reporting_group_name         ,us.ms_rit_region_mst_key         ,rm.region_name         ,us.ms_rit_sub_region_mst_key         ,sm.sub_region_name         ,tp.task_mst_key         ,ttm.task_type_name         ,ct.*         ,fm.task_status         ,fm.task_start_date         ,fm.task_end_date         ,srm.role_name rolename     users_master um     inner join ms_rit_user_skillset_map on um.userid = us.user_name     inner join dim_ms_rit_reporting_group_mst rg on us.ms_rit_reporting_group_mst_key = rg.ms_rit_reporting_group_mst_key         , upper(rg.active) in ('yes','1','y')     inner join dim_ms_rit_region_mst rm on us.ms_rit_region_mst_key = rm.ms_rit_region_mst_key         , upper(rm.active) in ('yes','1','y')     inner join dim_ms_rit_sub_region_mst sm on us.ms_rit_sub_region_mst_key = sm.ms_rit_sub_region_mst_key         , upper(sm.active) in ('yes','1','y')     inner join ms_rit_user_task_map tp on convert(varchar,um.userid) = tp.user_id     inner join ms_rit_create_task ct on ct.task_id = tp.task_mst_key     inner join wf_frm_28_mst fm on fm.task_id = ct.task_id     inner join sec_user_role sr on sr.user_id = um.username     inner join sec_role_mst srm on srm.role_code = sr.role_code     inner join ms_rit_task_type_master ttm on ct.task_type = ttm.task_type_id 

use union rid of duplicates

one solution check if have duplicates union using same query, if no rows removed not duplicates.

(select distinct(um.username)'user_name'         ,um.firstname + ' ' + um.lastname 'employee name'         ,us.user_name 'user_id'         ,us.ms_rit_reporting_group_mst_key         ,rg.reporting_group_name         ,us.ms_rit_region_mst_key         ,rm.region_name         ,us.ms_rit_sub_region_mst_key         ,sm.sub_region_name         ,tp.task_mst_key         ,ttm.task_type_name         ,ct.*         ,fm.task_status         ,fm.task_start_date         ,fm.task_end_date         ,srm.role_name rolename     users_master um     inner join ms_rit_user_skillset_map on um.userid = us.user_name     inner join dim_ms_rit_reporting_group_mst rg on us.ms_rit_reporting_group_mst_key = rg.ms_rit_reporting_group_mst_key         , upper(rg.active) in ('yes','1','y')     inner join dim_ms_rit_region_mst rm on us.ms_rit_region_mst_key = rm.ms_rit_region_mst_key         , upper(rm.active) in ('yes','1','y')     inner join dim_ms_rit_sub_region_mst sm on us.ms_rit_sub_region_mst_key = sm.ms_rit_sub_region_mst_key         , upper(sm.active) in ('yes','1','y')     inner join ms_rit_user_task_map tp on convert(varchar,um.userid) = tp.user_id     inner join ms_rit_create_task ct on ct.task_id = tp.task_mst_key     inner join wf_frm_28_mst fm on fm.task_id = ct.task_id     inner join sec_user_role sr on sr.user_id = um.username     inner join sec_role_mst srm on srm.role_code = sr.role_code     inner join ms_rit_task_type_master ttm on ct.task_type = ttm.task_type_id)      union  (select distinct(um.username)'user_name'         ,um.firstname + ' ' + um.lastname 'employee name'         ,us.user_name 'user_id'         ,us.ms_rit_reporting_group_mst_key         ,rg.reporting_group_name         ,us.ms_rit_region_mst_key         ,rm.region_name         ,us.ms_rit_sub_region_mst_key         ,sm.sub_region_name         ,tp.task_mst_key         ,ttm.task_type_name         ,ct.*         ,fm.task_status         ,fm.task_start_date         ,fm.task_end_date         ,srm.role_name rolename     users_master um     inner join ms_rit_user_skillset_map on um.userid = us.user_name     inner join dim_ms_rit_reporting_group_mst rg on us.ms_rit_reporting_group_mst_key = rg.ms_rit_reporting_group_mst_key         , upper(rg.active) in ('yes','1','y')     inner join dim_ms_rit_region_mst rm on us.ms_rit_region_mst_key = rm.ms_rit_region_mst_key         , upper(rm.active) in ('yes','1','y')     inner join dim_ms_rit_sub_region_mst sm on us.ms_rit_sub_region_mst_key = sm.ms_rit_sub_region_mst_key         , upper(sm.active) in ('yes','1','y')     inner join ms_rit_user_task_map tp on convert(varchar,um.userid) = tp.user_id     inner join ms_rit_create_task ct on ct.task_id = tp.task_mst_key     inner join wf_frm_28_mst fm on fm.task_id = ct.task_id     inner join sec_user_role sr on sr.user_id = um.username     inner join sec_role_mst srm on srm.role_code = sr.role_code     inner join ms_rit_task_type_master ttm on ct.task_type = ttm.task_type_id) 

Comments

Popular posts from this blog

scala - 'wrong top statement declaration' when using slick in IntelliJ -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

PySide and Qt Properties: Connecting signals from Python to QML -