If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > need a query.......

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-31-06, 06:46
Meena.s Meena.s is offline
Registered User
 
Join Date: Sep 2006
Posts: 87
need a query.......

Hi all,

I have a table which have the following data's for ex:
C:\Documents and Settings\Administrator>db2 select * from m1

EMPNO EMPNAME DEPT
----------- ---------- --------------------
1 meens db2
2 kapli db2
3 mini sql
4 jeeva sql
5 sam sql
6 ram sql

6 record(s) selected.
I need to query empno,empname where the dept is having atleast 3 employess.For ex. the query should return only the sql dept which is having 4 employees from the above table.

Any help....

Thanks and Regards
Meena.s
Reply With Quote
  #2 (permalink)  
Old 10-31-06, 08:08
umayer umayer is offline
Registered User
 
Join Date: Dec 2005
Posts: 273
try this:

SELECT EMPNO, EMPNAME
FROM m1
WHERE DEPT IN (
SELECT DEPT FROM m1
GROUP BY DEPT
HAVING COUNT(*) >= 3 )

or try this:

SELECT EMPNO , EMPNAME
FROM m1 a
INNER JOIN
( SELECT DEPT
FROM m1
GROUP BY DEPT
HAVING COUNT(*) >= 3 ) b
ON a.DEPT = b.DEPT
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On