Multiple select statements in Single query

boss picture boss · Nov 21, 2009 · Viewed 363.6k times · Source

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

sathish picture sathish · Nov 21, 2009
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