MySQL Forums
Forum List  »  Newbie

Re: Count from 3 diffrent tables
Posted by: Andrew Gilfrin
Date: July 23, 2005 12:05AM

mysql> select c1.id, c1.name, (select count(*) from table2 where site_afis = c1.id) as table2_count
-> , (select count(*) from table3 where site_afis = c1.id) as table3_count
-> from table1 c1;
+------+-------+--------------+--------------+
| id | name | table2_count | table3_count |
+------+-------+--------------+--------------+
| 1 | Row 1 | 2 | 1 |
| 2 | Row 2 | 1 | 2 |
| 3 | Row 3 | 2 | 3 |
+------+-------+--------------+--------------+
3 rows in set (0.02 sec)

Andrew Gilfrin
------------------
http://gilfster.blogspot.com
My MySQL related Blog

http://www.mysqldevelopment.com
MySQL Stored Procedure,Trigger, View.... (Just about most things these days) Information

Options: ReplyQuote


Subject
Written By
Posted
Re: Count from 3 diffrent tables
July 23, 2005 12:05AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.