I want to check which users have the most records in a database. So every user has a specific Id, and that Id is used as a reference in a few tables.
There are a few tables that contain a column UserId, like the table Exams, Answers, Questions, Classes, etc. Is it possible to count all the records with a specific UserId in all those tables?
;with cte as ( select rowsCount = count(*) from A where UserId = 1 union all select rowsCount = count(*) from B where UserId = 1 union all select rowsCount = count(*) from C where UserId = 1 ) select sum(rowsCount) from cte