October 10, 2011 at 6:08 am
Hi All,
I have a requirement like in my sample table
there are empid, firstname, lastname, salary, date joined.
Now in Sample table i want only the list of all duplicate records
where firstname and lastname is same.(i.e based on column specification).
Resultant Select query should contain columns,
empid, firstname, lastname, salary, date joined.
How can i achieve this?
October 10, 2011 at 6:17 am
How to post data/code on a forum to get the best help
http://www.sqlservercentral.com/articles/Best+Practices/61537/
October 10, 2011 at 6:22 am
Ha Ha ha:-)
Is this answer to my post or suggestion for how to post query in sqlservercentral.com..
Any way i am expecting answer for my post..
October 10, 2011 at 6:28 am
You may have to follow certain pattern to help you better!!!
Otherwise people wont take effort to create tables and data for you which would be areal example.
Answering your question,
you have to use Group by with having with count greater than 1. then get the empid(considering its unique) and joing the base table to get result set.
Sorry, no time to write a query as long as you are not ready to give the table schema and data.
October 10, 2011 at 6:32 am
sonymadhu (10/10/2011)
Hi All,I have a requirement like in my sample table
there are empid, firstname, lastname, salary, date joined.
Now in Sample table i want only the list of all duplicate records
where firstname and lastname is same.(i.e based on column specification).
Resultant Select query should contain columns,
empid, firstname, lastname, salary, date joined.
How can i achieve this?
Use COUNT() with OVER(), Partitioning by firstname and lastname. Select the results from a CTE or derived table where the row count per partition is greater than 1.
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
October 10, 2011 at 6:42 am
Hey frnds,
I am new to this site actually, thats the problem..
Just i followed how i post queries in other sites juz did the same here also..
at last i got answer for my post..
thanks to all...
select empid, firstname, lastname, salary, date joined
from sample a
where (select COUNT(*) from sample b where a.firstname=b.firstname and a.lastname=b.lastname)>1
October 10, 2011 at 6:56 am
sonymadhu (10/10/2011)
Hey frnds,I am new to this site actually, thats the problem..
Just i followed how i post queries in other sites juz did the same here also..
at last i got answer for my post..
thanks to all...
select empid, firstname, lastname, salary, date joined
from sample a
where (select COUNT(*) from sample b where a.firstname=b.firstname and a.lastname=b.lastname)>1
Don't do it like this, you will lose points. Your tutor will be looking for COUNT() with OVER(). Try it, if you have difficulty, post what you've tried so we can correct it for you.
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply