Poonam Bhatt
Poonam Bhatt

Reputation: 10302

union issue for getting total count

How can we count the total records of UNION of 2 select statement through query in MySql?

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

Upvotes: 1

Views: 511

Answers (3)

John Woo
John Woo

Reputation: 263723

is this what you want? Your question is to unclear to me.

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

Upvotes: 1

Minras
Minras

Reputation: 4346

You can use derived tables:

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

UPD: here's a fiddle

Upvotes: 2

Stelian Matei
Stelian Matei

Reputation: 11623

You could do something like

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

Upvotes: 0

Related Questions