SELECT
( SELECT
SUM(IF(status = 'Active', 1, 0)) AS `univ_active`,
SUM(IF(status = 'Inactive', 1, 0)) AS 'univ_inactive',
Count(*)
FROM online_university
)
AS tot_university,
( SELECT
SUM(IF(status = 'Active', 1,0)) AS `user_active`,
SUM(IF(status = 'Inactive', 1,0)) AS 'user_inactive'
Count(*)
FROM online_register_user)
AS tot_users
Result must be
univ_active=4 univ_inactive=2 tot_university=6
user_active=10 user_inactive=3 tot_users = 13
How can i get this? The above query returning ERROR: Operand should contain 1 column(s)
This to prepare report for a project from all tables returning Active, Inactive, Total records from the table. If this method is wrong then what shall i user? Any suggestion.
Subqueries can only return one column. You either need to do multiple subqueries, a join, or a cheap concat hack (
CONCAT_WS(',', SUM(IF(status = 'Active', 1,0)), SUM(IF(status = 'Inactive', 1,0))
) in a single subquery.