Selecting SUM+COUNT from one table and COUNT from another in Single query

Ace

I want to fetch Sum of age and total users which are active from users table and total number of png pictures from pictures table. I tried the following but it is giving me error. How can i do this in single query? I'm using PDO

SELECT
(SELECT SUM(age) AS age_sum,COUNT(*) AS total FROM users where type='active'),
(SELECT COUNT(*) AS pictotal FROM pictures where extension='png')

ERROR -> Operand should contain 1 column(s)

Floyd

SELECT
AA.age_sum, AA. total, BB.pictotal
FROM
(SELECT SUM(age) AS age_sum,COUNT(*) AS total FROM users where type='active') AA,
(SELECT COUNT(*) AS pictotal FROM pictures where extension='png') BB

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Selecting records from a table and then selecting a count of records from another table

From Dev

MySQL query - select from one, count from another table

From Dev

Count number of rows from another table in single query

From Dev

Select from one table and count from another

From Dev

Select * as well as count/sum from another table

From Dev

selecting records from main table and count of each row in another table

From Dev

SQL query with count() from another table

From Dev

Adding a count from another table to existing query

From Dev

MySQL join / sum value from one table colum with a count values from another

From Dev

MySQL count of count, use result from one table with another

From Dev

PostgreSQL count entries from one table for a given id and mutliple that by rates in another table and sum it all up

From Dev

PostgreSQL count entries from one table for a given id and mutliple that by rates in another table and sum it all up

From Dev

Query within another query to count amount of items from another table

From Dev

Display the details from one table and count from another table

From Dev

MySQL query to sum one column and count another column, from two tables, based on a common value?

From Dev

How to get count from another table (zero when no data) using single query in mysql?

From Dev

How to get count from another table (zero when no data) using single query in mysql?

From Dev

join count from one table to select from another - mysql

From Dev

Retriving the count from one table given a value from another

From Dev

select from one table, count from another where id is not linked

From Dev

Display 2 columns from one table having max count in column 3 and display computed sum of values from another table

From Dev

MYSQL join one colum from one table to two count() in another

From Dev

COUNT query with mysql with condition from one field from table

From Java

SQL query INSERT SELECT COUNT from one table to another row by row

From Dev

Count Row from another table

From Dev

Filter by count from another table

From Dev

Get count from another table

From Dev

MySQL Count values from one column with selecting a value from another column

From Dev

MySQL query with COUNT and join column from another table

Related Related

  1. 1

    Selecting records from a table and then selecting a count of records from another table

  2. 2

    MySQL query - select from one, count from another table

  3. 3

    Count number of rows from another table in single query

  4. 4

    Select from one table and count from another

  5. 5

    Select * as well as count/sum from another table

  6. 6

    selecting records from main table and count of each row in another table

  7. 7

    SQL query with count() from another table

  8. 8

    Adding a count from another table to existing query

  9. 9

    MySQL join / sum value from one table colum with a count values from another

  10. 10

    MySQL count of count, use result from one table with another

  11. 11

    PostgreSQL count entries from one table for a given id and mutliple that by rates in another table and sum it all up

  12. 12

    PostgreSQL count entries from one table for a given id and mutliple that by rates in another table and sum it all up

  13. 13

    Query within another query to count amount of items from another table

  14. 14

    Display the details from one table and count from another table

  15. 15

    MySQL query to sum one column and count another column, from two tables, based on a common value?

  16. 16

    How to get count from another table (zero when no data) using single query in mysql?

  17. 17

    How to get count from another table (zero when no data) using single query in mysql?

  18. 18

    join count from one table to select from another - mysql

  19. 19

    Retriving the count from one table given a value from another

  20. 20

    select from one table, count from another where id is not linked

  21. 21

    Display 2 columns from one table having max count in column 3 and display computed sum of values from another table

  22. 22

    MYSQL join one colum from one table to two count() in another

  23. 23

    COUNT query with mysql with condition from one field from table

  24. 24

    SQL query INSERT SELECT COUNT from one table to another row by row

  25. 25

    Count Row from another table

  26. 26

    Filter by count from another table

  27. 27

    Get count from another table

  28. 28

    MySQL Count values from one column with selecting a value from another column

  29. 29

    MySQL query with COUNT and join column from another table

HotTag

Archive