January 22, 2010 at 10:16 pm
the sample table looks like
1 malli o2o2020
2 malli 878hjh8
3 reddy ghhg5
4 reddy 56656
5 eswa ttt656
6 rama ettt
here i want to get only malli and reddy to get which was duplicate.but there was primary key and unique identifier for the same table.how cal i acheive this.Any one appreciated.
i want records exact like this
1 malli o2o2020
2 malli 878hjh8
3 reddy ghhg5
4 reddy 56656
Malleswarareddy
I.T.Analyst
MCITP(70-451)
January 23, 2010 at 3:18 am
did you try to search for a solution already?
If you type "find duplicate rows" in the search box (upper right side of the form) you'll find numerous solutions covering the subject.
We'll be glad to help you if you have trouble understanding how it works.
But I think if we just provide the solution won't help you in the long run...
To know how to look for an already existing solution that just needs to be modified is a programming skill as well...
January 23, 2010 at 3:34 am
Exactly!!! and moreover.. you are an 'ssc- addicted'. By now you should be knowing how to post data?
---------------------------------------------------------------------------------
January 23, 2010 at 5:03 am
no that all the article are not working for my request.i want to show all duplicates instead of that.
i already showed the above pattern how ca you achieve this.
Malleswarareddy
I.T.Analyst
MCITP(70-451)
January 23, 2010 at 5:20 am
So, which solution did you try with your data and where did you get stuck?
Please provide table definition, sample data, expected result and what you've tried so far as described in the first link in my signature.
January 23, 2010 at 7:01 am
Hi ,
i searched the duplcate calls but in my table i have an unique identifier and also i want to dsiplay like this
br_benficiaryname br_village br_id
malli gag 1234
malli gag 1456
so i want o get both records.with diff beneficiaryid
Malleswarareddy
I.T.Analyst
MCITP(70-451)
January 23, 2010 at 7:05 am
Hint:
A subquery that groups by whatever column 2 is called and does a filter HAVING COUNT(*) > 1
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
January 23, 2010 at 7:19 am
even i tried like this alo but i have unique identifier for a column name benfiaryid in the above result i want show the unqiue identfier for that colmun.iam not able to got result set .
there are another beneficiary visits table where the beneficaryid is updated
after getting duplicate records we can check which record is updated.so that other records we
want to remove.
Malleswarareddy
I.T.Analyst
MCITP(70-451)
January 23, 2010 at 7:46 am
malleswarareddy_m (1/23/2010)
even i tried like this alo but i have unique identifier for a column name benfiaryid in the above result i want show the unqiue identfier for that colmun.iam not able to got result set .
That's why I said a subquery.
Second hint. Join the subquery to the original table
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
January 23, 2010 at 9:42 am
Strong hint!
Write a query which returns the following result set:
malli 2
reddy 2
- then post it here.
For better assistance in answering your questions, please read this[/url].
Hidden RBAR: Triangular Joins[/url] / The "Numbers" or "Tally" Table: What it is and how it replaces a loop[/url] Jeff Moden[/url]
January 23, 2010 at 11:13 am
malleswarareddy_m (1/22/2010)
the sample table looks like1 malli o2o2020
2 malli 878hjh8
3 reddy ghhg5
4 reddy 56656
5 eswa ttt656
6 rama ettt
here i want to get only malli and reddy to get which was duplicate.but there was primary key and unique identifier for the same table.how cal i acheive this.Any one appreciated.
i want records exact like this
1 malli o2o2020
2 malli 878hjh8
3 reddy ghhg5
4 reddy 56656
Hey there, malleswarareddy_m...
Know why you keep getting non-coded answers to your simple problem? Find out by reading the following article...
http://www.sqlservercentral.com/articles/Best+Practices/61537/
Here's another example of how to post test data. While I was at it, I also included a solution for you. I still recommend you read the article at the link I posted above for your next post, though.
drop table #testdata
--===== Create the test data
SELECT *
INTO #TestData
FROM (
SELECT 1,'malli','o2o2020' UNION ALL
SELECT 2,'malli','878hjh8' UNION ALL
SELECT 3,'reddy','ghhg5' UNION ALL
SELECT 4,'reddy','56656' UNION ALL
SELECT 5,'eswa','ttt656' UNION ALL
SELECT 6,'rama','ettt' UNION ALL
SELECT 7,'homer','whatever' UNION ALL
SELECT 8,'homer','dodah' UNION ALL
SELECT 20,'hammer','nails' UNION ALL
SELECT 30,'homer','DOH!'
) testdata (RowNum, Name, SomeValue);
GO
--===== Solve the problem
WITH
cteDupeName AS
(
SELECT Name
FROM #TestData
GROUP BY Name
HAVING COUNT(*) > 1
)
SELECT source.RowNum, source.Name, source.SomeValue
FROM #TestData source
INNER JOIN cteDupeName dupe
ON source.Name = dupe.Name
ORDER BY source.RowNum;
GO
--Jeff Moden
Change is inevitable... Change for the better is not.
January 24, 2010 at 10:04 pm
Hi jeff,
yaa your solution is absolutly correct and i found the solution my self and writing the query like your same as your posted query.and this is a simplest solution but i wasted hours of time finally i got solution but i did n't post.
Thanks for all who responds my query.
Malleswarareddy
I.T.Analyst
MCITP(70-451)
January 24, 2010 at 11:40 pm
malleswarareddy_m (1/24/2010)
...but i wasted hours of time...
So, did you take the time to read the article I pointed you to so that doesn't happen anymore?;-)
--Jeff Moden
Change is inevitable... Change for the better is not.
January 24, 2010 at 11:59 pm
Why don't you share your solution with us for our enlightenment?
Saurabh Dwivedy
___________________________________________________________
My Blog: http://tinyurl.com/dwivedys
For better, quicker answers, click on the following...
http://www.sqlservercentral.com/articles/Best+Practices/61537
January 25, 2010 at 12:09 am
this is my query
with Duplicaterecords as
(
select br_beneficiaryname,br_beneficiarysurname,br_fathername,br_dob,br_districtid,br_mandalid,br_villageid,br_servicepointcode,br_beneficiaryid,br_dateofregistration,br_visitdate,
row_number() over(partition by br_districtid,br_mandalid,br_villageid,br_dob,br_beneficiaryname,br_beneficiarysurname,br_fathername order by br_districtid,
br_mandalid,br_villageid,br_beneficiaryname,br_dob,br_servicepointcode) as row from TELEMONITORING.beneficiaryregistration
where br_beneficiarytypeid=6
)
select * into #temp1 from Duplicaterecords
where row>1
order by br_servicepointcode
select a.br_beneficiaryname,a.br_beneficiarysurname,a.br_fathername,
a.br_dob,a.br_districtid,a.br_mandalid,a.br_villageid,
masterdata.hihlmain.district.districtname, masterdata.hihlmain.Mandal.mandalname,
masterdata.hihlmain.village.villagename,
a.br_servicepointcode,sp_servicepointname,a.br_beneficiaryid,a.br_dateofregistration,a.br_visitdate
from TELEMONITORING.beneficiaryregistration a
inner join #temp1 b on a.br_servicepointcode=b.br_servicepointcode
inner join telemonitoring.servicepointregistration on sp_servicepointcode=a.br_servicepointcode
inner join masterdata.hihlmain.district on masterdata.hihlmain.district.Districtid=a.br_districtid
inner join masterdata.hihlmain.Mandal on masterdata.hihlmain.mandal.mandalid=a.br_mandalid
inner join masterdata.hihlmain.village on masterdata.hihlmain.village.villageid=a.br_villageid
and a.br_beneficiaryname=b.br_beneficiaryname
and a.br_beneficiarysurname=b.br_beneficiarysurname
and a.br_fathername=b.br_fathername
and a.br_districtid=b.br_districtid
and a.br_mandalid=b.br_mandalid
and a.br_villageid=b.br_villageid
and a.br_servicepointcode=b.br_servicepointcode
group by
a.br_districtid,a.br_mandalid,a.br_villageid,a.br_servicepointcode,
a.br_beneficiaryname,a.br_beneficiarysurname,a.br_fathername,a.br_dob,
a.br_beneficiaryid,a.br_dateofregistration,a.br_visitdate,sp_servicepointname,
masterdata.hihlmain.district.districtname, masterdata.hihlmain.Mandal.mandalname,
masterdata.hihlmain.village.villagename
drop table #temp1
Malleswarareddy
I.T.Analyst
MCITP(70-451)
Viewing 15 posts - 1 through 15 (of 20 total)
You must be logged in to reply to this topic. Login to reply