combining multiple columns in one query

hellomynameis :

Table A

+------------+--------------+--------------+
+  ID        +  Name        +   Company ID +
+------------+--------------+--------------+
+   1        +  Steve       +      1       +
+   2        +  Mile        +      2       +
+   3        +  Steve       +      2       +
+   4        +  Del Piero   +      2       +
+   5        +  Jack        +              +
============================+==============+

Table B

+------------+--------------+
+  ID        +  Company     +
+------------+--------------+
+   1        +  A           +
+   2        +  B           +
============================+

What I want

+----------+------------+----------------+
+ # of id  +  # OF Name +  # of B Company+
+----------+------------+----------------+
+ 5        +  4         +  3             +
+========================================+

I have tried Union//Union All

SELECT count(id), count(name) FROM table A
UNION 
SELECT count(company) FROM table B where company = 'B'

I should keep these columns but Union doesn't allow a different number of columns.

Any ideas would be appreciated

Ivan :

Try this one

SELECT count(id),
count(name),
(SELECT count(company) FROM table B where company)
FROM table A

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=21295&siteId=1