COUNT(*) from multiple tables in MySQL

前端 未结 5 1168
旧时难觅i
旧时难觅i 2020-11-30 03:50

How do I go about selecting COUNT(*)s from multiple tables in MySQL?

Such as:

SELECT COUNT(*) AS table1Count FROM table1 WHERE someCondition
JOIN?? 
         


        
5条回答
  •  南方客
    南方客 (楼主)
    2020-11-30 04:24

    You can do it by using subqueries, one subquery for each tableCount :

    SELECT
      (SELECT COUNT(*) FROM table1 WHERE someCondition) as table1Count, 
      (SELECT COUNT(*) FROM table2 WHERE someCondition) as table2Count,
      (SELECT COUNT(*) FROM table3 WHERE someCondition) as table3Count
    

提交回复
热议问题