Oct 20, 2006 #1 james0816 Programmer Joined Jan 9, 2003 Messages 295 Location 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
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
Oct 20, 2006 #2 feherke Programmer Joined Aug 5, 2002 Messages 9,541 Location RO 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. http://rootshell.be/~feherke/ Upvote 0 Downvote
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. http://rootshell.be/~feherke/