How to do a count on a union query

前端 未结 6 1062
谎友^
谎友^ 2020-12-28 12:32

I have the following query:

select distinct profile_id from userprofile_...

union

select distinct profile_id from productions_...

How wou

6条回答
  •  感情败类
    2020-12-28 12:58

    Best solution is to add count of two query results. It will not be a problem if the table contains large number of records. And you don't need to use union query. Ex:

    SELECT (select COUNT(distinct profile_id) from userprofile_...) + 
    (select COUNT(distinct profile_id) from productions_...) AS total
    

提交回复
热议问题