I need to select the counts from two tables that share a common column which is the clientId
and group the totals by the clientIds
for a given day and the dateadded
column in both tables is in the datetime format.
For example the result should show:
ClientId Total1 Total2
aaaa 1 2
bbbbb 43 45
ccccc 123 355
etc. for 2011-03-25
what I currently have is
select
(select clientid,count(*) as total1 from TFeed where dateadded = getdate()
group by clientId),
(select clientId, count(*) as total2 from WFeed where dateadded = getdate()
group by clientid)
This is of course wrong. ERROR: only one expression can be specified in the select list when the subquery is not introduced with EXISTS. Also for consideration, these are very large tables - over 3 million records and growing. Any help appreciated
EDIT:
about the time - if dateadded = '2011-03-25 12:00:34 0011', how can I compare the time to get dateadded = @getdate() and select all the records for today.
while my query is still running - off topic question...since this is a reporting query and I want to run it regularly to update totals so that when client opens web page or clicks on report it would deliver totals without having to run the query and just select the last totals from a database. do I then need to a have a different query or run this every hour or so.