Muhammad Raheel
Muhammad Raheel

Reputation: 19882

Multiple Count from multiple tables

I have two tables and i am trying to get count from both tables. Means count from first table then count from 2nd table and result should look like this.

Count(users.name)   Count(users_types)
        5                    8

But my query brings this result

Count(users.name)   Count(users_types)
        8                    8

Here is my query

select count(users.users),
count(users_types.users_types)
form users , users_types  

How can i get correct result?

Upvotes: 1

Views: 149

Answers (3)

Muhammad Raheel
Muhammad Raheel

Reputation: 19882

Use a sub query like this

select
  count(users.users)    Users,
  (select
     count(users_types.users_types)
   from teams)    UsersTypes
from users

Upvotes: 0

Addicted
Addicted

Reputation: 1704

select (select count(*) cnt1 from table1),
 (select count(*) cnt2 from table2)

Upvotes: 1

Sudhir Bastakoti
Sudhir Bastakoti

Reputation: 100175

try:


select
(select count(users.users) from users),
(select count(users_types.users_types) form users_types)

Upvotes: 1

Related Questions