Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

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

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
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    Post subject: to get count of rows in another table for a key in 1 table
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    Post subject:
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    Post subject:
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    Post subject: Reply to: to get count of rows in another table for a key in
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    Post subject:
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    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Count the length of the record & ... sreekusr DFSORT/ICETOOL 4 Thu Mar 23, 2017 7:52 pm
No new posts Display FTP Session Count within TSO Yolanda Harvey TSO/ISPF 3 Fri Mar 10, 2017 10:31 pm
No new posts To display values of multiple rows in... vinu78 DB2 2 Thu Mar 09, 2017 1:20 pm
No new posts how to send just 10 rows in a CICS sc... Megha Gupta CICS 5 Thu Feb 23, 2017 6:57 pm
No new posts Join of more than one table dibyendumandal11111 DB2 6 Mon Feb 13, 2017 11:36 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us