September 21, 2010 at 1:41 am
name ageempcpdemobno
A11111
A11112
A21111
B21111
B11121
B11111
C11112
D11112
D22111
this is the table above .
i want to achive 2 task:
1) result set where name ,age and empcode are same for more then once
2) where all the columns r same more then once
these is a dumy table but in actual table this situation
is posible .. hope u ll get the scenario.
September 21, 2010 at 2:10 am
You're looking for the HAVING clause
SELECT name,Age,empcode FROM tbl GROUP BY name, age, empcode HAVING count(*) > 1
Never stop learning, even if it hurts. Ego bruises are practically mandatory as you learn unless you've never risked enough to make a mistake.
For better assistance in answering your questions[/url] | Forum Netiquette
For index/tuning help, follow these directions.[/url] |Tally Tables[/url]
Twitter: @AnyWayDBA
September 21, 2010 at 4:38 am
yes this is ok but i want those data which is same Eg:
name and age and emp three same ... this three combine to make a unique data , and i want those data which is duplicate to combination of this combine three fields.
Eg:
name1 10 111
name1 10 111
September 21, 2010 at 8:13 am
I guess I don't understand, but that looks like what Craig posted. Could you try to explain it again?
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
- Theodore Roosevelt
Author of:
SQL Server Execution Plans
SQL Server Query Performance Tuning
September 21, 2010 at 9:55 am
I don't see the problem either, unless you just need to output all the original rows. If so, you can add an outer query that joins to a sequential numbers / tally table to "explode" to the original # of rows:
SELECT dups.*
FROM (
<original_query>
) AS dups
INNER JOIN sequentialNumber sn ON sn.[Number] BETWEEN 1 AND [Count]
ORDER BY name, ...
Scott Pletcher, SQL Server MVP 2008-2010
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply