联合问题以获得总数

时间:2012-02-15 10:25:19

标签: mysql

如何通过MySql中的查询计算2个select语句的UNION总记录?

(select name, phone from table1) UNION (select name, phone from table2)

3 个答案:

答案 0 :(得分:2)

您可以使用派生表:

SELECT COUNT(*)
FROM (
  (select name, phone from table1) 
  UNION 
  (select name, phone from table2)
  ) AS combined_table

UPD:这是fiddle

答案 1 :(得分:1)

这是你想要的吗?你的问题不明确。

SELECT COUNT(*) as TotalRecordCount
FROM
     (select name, phone from table1
          UNION 
     select name, phone from table2) as UnionTable

答案 2 :(得分:0)

您可以执行类似

的操作
SELECT COUNT(*) FROM
(
    (select name, phone from table1) UNION (select name, phone from table2)  
)