| Author |
Topic |
|
w1102157
Yak Posting Veteran
80 Posts |
Posted - 2012-01-18 : 06:16:30
|
| I am running a query where i am joining few tables to the fact table and i get the duplicate in the result as shown belowkey Org FD Desc Age Let LetDes 18xx 85 17/09/2012 1.. NULL 20 6.. Al 8xx 85 17/09/2012 1.. NULL 20 6.. Al 8xx 85 11/12/2011 1.. NULL 45 6.. Al 8xx 85 09/01/1999 1.. NULL 32 6.. Al 8xx 85 17/07/1995 1.. NULL 12 6.. Al as you can see the first two rows in the table are duplicates how can i remove these?thank you |
|
|
DonAtWork
Master Smack Fu Yak Hacker
2167 Posts |
Posted - 2012-01-18 : 06:41:57
|
| GROUP BY or ROW_NUMBER OVER()http://weblogs.sqlteam.com/jeffs/archive/2008/05/13/question-needed-not-answer.aspxHow to ask: http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspxFor ultra basic questions, follow these links.http://www.sql-tutorial.net/ http://www.firstsql.com/tutor.htm http://www.w3schools.com/sql/default.asp |
 |
|
|
w1102157
Yak Posting Veteran
80 Posts |
Posted - 2012-01-18 : 06:42:02
|
| I have presented the result more clear below the first two rows are duplicate how can i take these duplicates out? or even better do the query so it excludes such duplicateskey Org FD Desc Age Let LetDes 18xx 85 17/09/2012 1.. NULL 20 6.. Al 8xx 85 17/09/2012 1.. NULL 20 6.. Al 8xx 85 11/12/2011 1.. NULL 45 6.. Al 8xx 85 09/01/1999 1.. NULL 32 6.. Al 8xx 85 17/07/1995 1.. NULL 12 6.. Al |
 |
|
|
w1102157
Yak Posting Veteran
80 Posts |
Posted - 2012-01-18 : 06:42:35
|
| DonAtWork how do you mean?thanks |
 |
|
|
DonAtWork
Master Smack Fu Yak Hacker
2167 Posts |
Posted - 2012-01-18 : 06:43:51
|
| Now show us the query you used to get your data, we can show you how to get rid of the duplicates.http://weblogs.sqlteam.com/jeffs/archive/2008/05/13/question-needed-not-answer.aspxHow to ask: http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspxFor ultra basic questions, follow these links.http://www.sql-tutorial.net/ http://www.firstsql.com/tutor.htm http://www.w3schools.com/sql/default.asp |
 |
|
|
w1102157
Yak Posting Veteran
80 Posts |
Posted - 2012-01-18 : 06:45:05
|
| DonAtWork the ROW_NUMBER OVER() will just put a squence number infornt of it it will still be a duplicate when the manager has a look at it |
 |
|
|
DonAtWork
Master Smack Fu Yak Hacker
2167 Posts |
Posted - 2012-01-18 : 06:53:56
|
| create table #foo (yak int)insert into #foo(yak )values (1),(2),(3),(4),(4),(5)select * from #fooselect yak from(select yak, ROW_NUMBER() OVER(PARTITION BY yak ORDER BY yak ) as rnfrom #foo )xwhere rn = 1drop table #foohttp://weblogs.sqlteam.com/jeffs/archive/2008/05/13/question-needed-not-answer.aspxHow to ask: http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspxFor ultra basic questions, follow these links.http://www.sql-tutorial.net/ http://www.firstsql.com/tutor.htm http://www.w3schools.com/sql/default.asp |
 |
|
|
w1102157
Yak Posting Veteran
80 Posts |
Posted - 2012-01-18 : 10:00:08
|
| DonAtWorkbelow is the query i am runningSELECT dbo.F.[Key], dbo.N.Org, dbo.D.FD,dbo.R.[Desc], dbo.F.Age, dbo.Di.Let, dbo.Dia.LetDes, dbo.F.1FROM dbo.Fact INNER JOIN dbo.N ON dbo.F.Orgkey = dbo.N.OrgKey INNER JOIN dbo.R ON dbo.F.Key = dbo.R.RKey INNER JOIN dbo.D ON dbo.F.DKey = dbo.DD.DKey |
 |
|
|
w1102157
Yak Posting Veteran
80 Posts |
Posted - 2012-01-18 : 11:08:44
|
| anyone???? |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
w1102157
Yak Posting Veteran
80 Posts |
Posted - 2012-01-18 : 11:40:32
|
| select distinct row? |
 |
|
|
DonAtWork
Master Smack Fu Yak Hacker
2167 Posts |
Posted - 2012-01-18 : 14:35:22
|
Sorry, had to do actual work.Just add DISTINCT to your SELECT statement like brett suggested.SELECT DISTINCT dbo.F.[Key], dbo.N.Org, dbo.D.FD,dbo.R.[Desc], dbo.F.Age,dbo.Di.Let, dbo.Dia.LetDes, dbo.F.1FROM dbo.Fact INNER JOINdbo.N ON dbo.F.Orgkey = dbo.N.OrgKey INNER JOINdbo.R ON dbo.F.Key = dbo.R.RKey INNER JOINdbo.D ON dbo.F.DKey = dbo.DD.DKey http://weblogs.sqlteam.com/jeffs/archive/2008/05/13/question-needed-not-answer.aspxHow to ask: http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspxFor ultra basic questions, follow these links.http://www.sql-tutorial.net/ http://www.firstsql.com/tutor.htm http://www.w3schools.com/sql/default.asp |
 |
|
|
w1102157
Yak Posting Veteran
80 Posts |
Posted - 2012-01-19 : 07:28:35
|
| thanks mate |
 |
|
|
|