Assuming every name appears at least once in both tables, then this should work:
SELECT
d1.name,
d1_count,
d2_count,
d1_count + d2_count As total
FROM
(SELECT name, COUNT(1) As d1_count FROM @Raj GROUP BY name) As d1
INNER JOIN (SELECT name, COUNT(1) As d2_count FROM @Kri GROUP BY name) As d2
ON d1.name = d2.name
;
If any name could appear in only one table, you'll need to use an
OUTER JOIN
instead:
SELECT
IsNull(d1.name, d2.name) As name,
IsNull(d1_count, 0) As d1_count,
IsNull(d2_count, 0) As d2_count,
IsNull(d1_count, 0) + IsNull(d2_count, 0) As total
FROM
(SELECT name, COUNT(1) As d1_count FROM @Raj GROUP BY name) As d1
FULL OUTER JOIN (SELECT name, COUNT(1) As d2_count FROM @Kri GROUP BY name) As d2
ON d1.name = d2.name
;
Visual Representation of SQL Joins[
^]