在多个表中使用COUNT

时间:2012-01-07 23:12:43

标签: php sql count

我有以下代码来计算我的JB_Employer表中的记录数,但我还想将第二个(可能是第三个)表中的记录总数添加到此表中。

SELECT COUNT( * ) AS 'Number of employees'
FROM JB_Employer
WHERE Employer_ID >0

此外,如果有人可以建议我如何把它放到PHP中,我会很感激,有点麻烦搞清楚。

1 个答案:

答案 0 :(得分:1)

SELECT (
SELECT count(*) from table1
) as `table1_count`, (
SELECT count(*) from table2
) as `table2_count`

如果你想加起来

SELECT (
SELECT count(*) from table1
) + (
SELECT count(*) from table2
) as `total_count`