You are viewing this site as a guest. You can still ask questions and help others! Join our Dev2Dev IT Community to receive your own blog, share your knowledge, and much more.

Help me with this SQL

1 reply [Last post]
krispsoftpro's picture
User offline. Last seen 6 years 40 weeks ago. Offline
Joined: 09/01/2008
Posts: 6

Hi I have a table called EMPDET with Emplid and Deptid as keys and values are as shown below.

Emplid Deptid Desc
1 A TEST
2 A TEST
3 A ABC
4 A TEST
5 B XYZ
6 B XYZ
7 B xyz
8 C TEST2
9 C STH
10 C TEST2
11 D STG
12 D STG
13 D STG

I need to write a query which will fetch below results. It should pick only dupilcate combination

Expected results:

A TEST
A ABC
C STH
C TEST2

Thanks,
Kris

Guest's picture
Guest (not verified)
Re: Help me with this SQL

Try this

Select deptid, desc from EMPDET group by deptid, desc having count(deptid, desc) >1 .

Aman