boss boss - 3 months ago 20
MySQL Question

Multiple select statements in Single query

I am generating a report in php (mysql),

ex:

`select count(id) as tot_user from user_table
select count(id) as tot_cat from cat_table
select count(id) as tot_course from course_table`


Like this I have 12 tables.

Can i make it in single query. If i did? Process gets slow?

Answer
SELECT  (
    SELECT COUNT(*)
    FROM   user_table
    ) AS tot_user,
    (
    SELECT COUNT(*)
    FROM   cat_table
    ) AS tot_cat,
    (
    SELECT COUNT(*)
    FROM   course_table
    ) AS tot_course