Welcome to WebmasterWorld Guest from 54.224.234.8

Forum Moderators: open

Message Too Old, No Replies

Usind count and union

Return two results instead of one?

     
11:20 am on Jan 24, 2006 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Jan 7, 2004
posts:933
votes: 0


select count(id) from db1 where p5!='0' UNION select count(id) from db2 where p5!='0'

I am stuck because just notice that this query will return two values, the value of the first select and the value of the second select.

This is what Mysql shows:


count(id)
43
5

How can I add these two values to get 48

12:23 pm on Jan 24, 2006 (gmt 0)

Senior Member

WebmasterWorld Senior Member txbakers is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Sept 1, 2001
posts:4392
votes: 0


Most likely you will need to do the query twice, and set the value to a variable each time, then add the variables.
5:15 pm on Jan 24, 2006 (gmt 0)

Preferred Member

10+ Year Member

joined:Nov 12, 2004
posts:393
votes: 0


The UNION operator merges the results of two or more queries. What you want to do is just add the results together.

SELECT (select count(id) from db1 where p5!='0') +
(select count(id) from db2 where p5!='0')

1:06 pm on Jan 25, 2006 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Jan 7, 2004
posts:933
votes: 0


Thanks Syber, it works like a charm!