IT Community - Software Programming, Web Development and Technical Support

How can count a column from two tables in SQL Server?

This is a discussion on How can count a column from two tables in SQL Server? within the Database Support forums, part of the Web Development category; How can count a column from two tables in SQL Server?...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Web Development > Database Support

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 07-24-2007, 06:31 AM
mobilegeek mobilegeek is offline
D-Web Analyst
 
Join Date: Jun 2007
Posts: 205
mobilegeek is on a distinguished road
Question How can count a column from two tables in SQL Server?

How can count a column from two tables in SQL Server?
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-24-2007, 06:48 AM
oxygen oxygen is offline
D-Web Architect
 
Join Date: Jun 2007
Posts: 633
oxygen is on a distinguished road
Default Re: How can count a column from two tables in SQL Server?

I have two tables namely emp and dept which have a common column “deptno”. I need to count the deptno from those two tables.

Here is the sample code.

Select sum (subcount) as totalcount from
(
select deptno, count(*) as subcount from emp group by deptno
union all
select deptno, count(*) as subcount from dept group by deptno
)
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
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

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Foreign key column leoraja8 Database Support 6 10-15-2007 11:27 PM
Can I nest tables within tables? oxygen HTML, CSS and Javascript Coding Techniques 2 07-27-2007 03:33 AM
What is the Query to display all tables and Database names in server use sql? kingmaker Database Support 2 07-23-2007 10:57 PM
How to retrive tables name with row count:(content) kingmaker Database Support 1 07-23-2007 07:29 AM
How to Create temporary tables in SQL Server 2005? oxygen Database Support 2 07-23-2007 01:13 AM


All times are GMT -7. The time now is 07:07 AM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0