Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Count Records from two tables

Status
Not open for further replies.

james0816

Programmer
Jan 9, 2003
295
US
I have two tables and I want to count the number of records where field1 = 1.

tbl1 field1
1
2
1
0

tbl2 field1
0
0
1

Result should be 3

Can someone help with the right coding?

thx
 
Hi

Code:
[b]select[/b]
sum(count)
[b]from[/b] (
  [b]select[/b]
  count(*) count
  [b]from[/b] tbl1
  [b]where[/b] field1=1
  [b]union all[/b]
  [b]select[/b]
  count(*)
  [b]from[/b] tbl2
  [b]where[/b] field1=1
) foo;

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top