Ryan A wrote:

Hi,
This is my first post here so forgive me if its too simple or not right.

basically what i do is:
SELECT COUNT(*) FROM table1 where cno=3;
(and dumping it into a variable $theResult - I am using PHP)
and it gives me the result, but now i need to do this in 5 tables...

I can of course run 5 count statements but was wondering if I can do the
whole thing in one statement?
A friend of mine told me to try "union" but when i go to the documentation
of union I cant understand much and it says "UNION is implemented in MySQL
4.0.0" I have no idea what version i have.

SHOW VARIABLES LIKE 'version'


The 5 tables are pretty much the same and have the same "cno" field that i
need and are named table1,table2,table3,table4,table5

SELECT COUNT(*) FROM table1 WHERE cno = 3 UNION SELECT COUNT(*) FROM table2 WHERE cno = 3 UNION SELECT COUNT(*) FROM table3 WHERE cno = 3 UNION SELECT COUNT(*) FROM table4 WHERE cno = 3 UNION SELECT COUNT(*) FROM table5 WHERE cno = 3

this will return 5 rows in result, f.e.:

COUNT(*)
--------
12
10
9
23
7


if you want all COUNTS as one row then you have to use f.e. MERGE table type (http://www.mysql.com/doc/en/MERGE.html)


SELECT COUNT(*) FROM tablemerge WHERE cno = 3

this would return f.e:

COUNT(*)
--------
61




Can anybody help me please? Thanks in advance.


cheers,
-Ryan



We will slaughter you all! - The Iraqi (Dis)information ministers site
http://MrSahaf.com





--
Sebastian Mendel

www.sebastianmendel.de
www.tekkno4u.de
www.nofetish.com


-- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]



Reply via email to