We help IT Professionals succeed at work.

count of subquery?

pillmill
pillmill asked
on
I am trying to an Intersection in Mysql by the following query:

SELECT * FROM
(SELECT DISTINCT var1 FROM table1)
UNION ALL
(SELECT DISTINCT var1 FROM table2 ) AS table3

GROUP BY table3.var1 HAVING COUNT(*)>1

How do I get a count of the number of rows returned?

Comment
Watch Question

Billing Engineer
GOLD EXPERT
Most Valuable Expert 2014
Top Expert 2009
Commented:
this should do:
select count(*) from ( <your query from above> )

otherwise, you might want to clarify what you really need with data samples.
Armand GSenior Developer
BRONZE EXPERT
Commented:
angelllll solution is good, but we can simplify further: I replace your * with COUNT(*).

SELECT COUNT(*) FROM
(SELECT DISTINCT var1 FROM table1)
UNION ALL
(SELECT DISTINCT var1 FROM table2 ) AS table3

GROUP BY table3.var1 HAVING COUNT(*)>1
awking00Information Technology Specialist
BRONZE EXPERT
Commented:
See attached.
query.txt

Explore More ContentExplore courses, solutions, and other research materials related to this topic.