I have two tables that I need to run query against each. The output of these two queries then need to be intersected and sorted based on the the number of occurrences of names found in both tables.
For example:
Query 1:
select * from userA
group by name
order by count(name) desc
---------------------------
ID | name | count(name)
---------------------------
1 | John | 2
2 | Mike | 1
3 | Laura | 1
---------------------------
Query 2:
select * from userB
group by name
order by count(name) desc
---------------------------
ID | name | count(name)
---------------------------
3 | Laura | 3
1 | John | 1
5 | Peter | 1
---------------------------
Query 3:
select * from userA
group by name
order by count(name) desc
intersect
select * from userB
group by name
order by count(name) desc
---------------------------
ID | name | count(name)
---------------------------
1 | John | 1
3 | Laura | 1
---------------------------
The problem is the intersect will re-run the count function discarding the count run from each query. What I'd like to see is the following output:
---------------------------
ID | name | count(name)
---------------------------
3 | Laura | 4
1 | John | 3
---------------------------
Does anyone know how to accomplish this?