在Mysql中添加两个不同查询的结果

在Mysql中添加两个不同查询的结果,mysql,Mysql,我在写查询时遇到困难。我一直在与UNION合作处理两个问题,它们都很好。当我尝试添加两个查询的结果时,我的问题出现了 以下是我自己的一些解释 //Query 1 select count(id) from table1 <-- This gives a result of 2 //Query 2 select count(id) from table2 <-- This gives a result of 1 //What I want to do is to add

我在写查询时遇到困难。我一直在与UNION合作处理两个问题,它们都很好。当我尝试添加两个查询的结果时,我的问题出现了

以下是我自己的一些解释

//Query 1
select count(id) from table1   <-- This gives a result of 2 
//Query 2
select count(id) from table2   <-- This gives a result of 1


//What I want to do is to add the two queries (2 + 1 = 3):
(select count(id) from table1) + (select count(id) from table2) <-- Which gives a result of 3.
我想我不应该用“+”号。有没有办法做到这一点?
多谢各位

您应该对整个查询进行选择:

SELECT (SELECT COUNT(id) FROM table1) + (SELECT COUNT(id) FROM table2) AS count
试一试

SELECT (SELECT COUNT(id) FROM table1) + (SELECT COUNT(id) FROM table2) AS count
SELECT (select count(id) from table1) + (select count(id) from table2) from dual;