1

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?

3 Answers 3

1

try:


select
(select count(users.users) from users),
(select count(users_types.users_types) form users_types)
Sign up to request clarification or add additional context in comments.

3 Comments

This works fine, but slows down the query significantly when the tables contains large amount of data. The original question seems to want it done without the speed issue.
well, nothing as such is mentioned in the question..!
Nothing wrong with your answer, but why not add the alternative answer that allows for faster results.
1
select (select count(*) cnt1 from table1),
 (select count(*) cnt2 from table2)

Comments

0

Use a sub query like this

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.