单个查询中的多个选择语句

2021-11-20 00:00:00 mysql

我正在用 php (mysql) 生成报告,

I am generating a report in php (mysql),

例如:

`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`

像这样我有 12 张桌子.

Like this I have 12 tables.

我可以在单个查询中创建它吗?如果我做了?进程变慢?

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

推荐答案

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

相关文章