IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

to get count of rows in another table for a key in 1 table


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
i_at_forum

New User


Joined: 29 Dec 2005
Posts: 10

PostPosted: Mon Feb 09, 2009 11:59 am
Reply with quote

I have 2 tables, DEPT & EMPLOYEE.

DEPT:
Dept Name
Dept No
Dept Loc

EMPLOYEE:
Employee Name
Employee Address
Salary
Dept No


I need an SQL to display Dept Name, Dept Loc, Dept No along with count of employees in each Dept.
Can anyone provide me with the query.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Mon Feb 09, 2009 2:35 pm
Reply with quote

Quote:

Can anyone provide me with the query

better than that, we can help you build your own query. what do you have so far?
Back to top
View user's profile Send private message
Srihari Gonugunta

Active User


Joined: 14 Sep 2007
Posts: 295
Location: Singapore

PostPosted: Mon Feb 09, 2009 3:29 pm
Reply with quote

Please try the following query.

Code:
SELECT A.DEPTNAME,A.DEPTNO,A.DEPTLOC,B.CNT FROM
DEPT A, (SELECT DEPTNO, COUNT(*) as CNT from EMPLOYEE
GROUP BY DEPTNO) AS B
WHERE A.DEPTNO=B.DEPTNO
Back to top
View user's profile Send private message
naveengec

New User


Joined: 24 Mar 2007
Posts: 35
Location: pune

PostPosted: Mon Feb 09, 2009 3:35 pm
Reply with quote

Please try it...

select dept_name, dept_loc, dept_No, (select count(B.DEPT_NO) FROM EMPLOYEE B WHERE A.DEPT_NO=B.DEPT_NO) AS COUNT_EMP
FROM DEPT A
Back to top
View user's profile Send private message
i_at_forum

New User


Joined: 29 Dec 2005
Posts: 10

PostPosted: Tue Feb 10, 2009 6:36 pm
Reply with quote

thank you...
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts Load new table with Old unload - DB2 DB2 6
No new posts To get the count of rows for every 1 ... DB2 3
No new posts Pulling a fixed number of records fro... DB2 2
No new posts To find whether record count are true... DFSORT/ICETOOL 6
No new posts Multiple table unload using INZUTILB DB2 2
Search our Forums:

Back to Top