August 9, 2016 at 6:16 pm
I have 4 separate tables that are related to each other. I want to return a count of each record in a table. Yet, return the answer in one query. What is the best method of going about this. I am interested in evaluating the logic necessary.
August 9, 2016 at 8:11 pm
smiF (8/9/2016)
I have 4 separate tables that are related to each other. I want to return a count of each record in a table. Yet, return the answer in one query. What is the best method of going about this. I am interested in evaluating the logic necessary.
Here are two hints:
select (select 1 as column_name) as column_subquery;
select count(*) from dbo.table_name;
There are no special teachers of virtue, because virtue is taught by the whole community.
--Plato
August 10, 2016 at 6:45 am
For a simple count of the tables, you can use something like this:
SELECT t.name AS Table_Name, SUM(row_count) AS Row_Count
FROM sys.dm_db_partition_stats s
JOIN sys.tables t ON s.object_id = t.object_id
WHERE index_id IN (0,1)--heap or clustered index
AND t.name IN ('Table1', 'Table2')
GROUP BY t.name;
August 10, 2016 at 8:32 am
Thanks everyone for the replies...I could not see around this corner. This is the logic I was looking for..
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply