Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 repeated records

Author  Topic 

divyaat
Starting Member

1 Post

Posted - 2014-03-05 : 12:07:52
Hi ,

Could you please help me in finding the solution for the below query?

It displays repeated records.

Kindly help me on this since am a beginner.

select distinct ku.username,rro.role_name,rp.resource_type_code,kr.region_name,kc.currency_name,
fcr.cost_rule_id RULE,fcr.rate current_rate,pp.project_name,kou.org_unit_name ORG_UNIT
from
knta_users ku,RSC_RESOURCES rr,RSC_RESOURCE_ROLES rrr,RSC_ROLES rro,
RSC_POSITIONS rp,KNTA_REGIONS kr,KCST_CURRENCIES kc,FM_COST_RATES fcr,FM_COST_RULES fcru,
PM_PROJECTS pp,KRSC_ORG_UNITS kou

where

ku.user_id = rr.user_id
and rr.resource_id = rrr.resource_id
and rrr.role_id = rro.role_id
and rro.role_id = rp.role_id
and ku.region_id = kr.region_id
and kr.currency_id = kc.currency_id
and kc.currency_code = fcr.currency_code
and fcr.cost_rule_id = fcru.cost_rule_id
and kr.region_id = pp.region_id
and ku.manager_user_id = kou.manager_id

Kind Regards

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2014-03-05 : 12:11:46
It displays repeated records because you have a one to many relationship between two or more of the tables. You'll need to determine which rows you'll want to keep. ROW_NUMBER() function can be helpful for this.

And you need to start using proper JOIN syntax. Join conditions should not be in the WHERE clause. You should have only one table in the FROM. Use joins for the other tables.

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

maunishq
Yak Posting Veteran

71 Posts

Posted - 2014-03-05 : 13:51:44
Which database are you using?

=======================
Not an Expert, Just a learner.
!_(M)_!
Go to Top of Page
   

- Advertisement -