mysql - 如何对联合查询进行计数

我有以下问题:

select distinct profile_id from userprofile_...

union

select distinct profile_id from productions_...

我如何计算结果总数?


最佳答案:

如果您想要所有记录的总计数,那么您可以这样做:

SELECT COUNT(*)
FROM
(
    select distinct profile_id 
    from userprofile_...

    union all

    select distinct profile_id 
    from productions_...
) x