SELECT t.value, count(*) as users_count
FROM users u
JOIN (
SELECT d1.text as value, d1.user_id FROM data1 d1
UNION
SELECT d2.name as value, d2.user_id FROM data2 d2
) t on t.user_id = u.id
GROUP BY t.value
ORDER BY users_count DESC
select d.value,
count(*) users_count
from user u
left join (select user_id, data1.text value from data1
union all
select user_id, data2.name value from data2
) d on d.user_id = u.id
group by d.value