Hello to everyone of you here!! I have a question that is breaking my head... the story is... I have two tables... in both tables I have a field that contain a number... what I want to know is to know how many records on both tables have this number...
SELECT count(*) FROM DBO.temporal_announcements, DBO.announcements WHERE temporal_announcements.user_unique_key = '07262007-020830' AND announcements .under_account = '07262007-020830'
but this return invalid data... a number that is not correct... what can I do... I just want to count how many records has this number in x field in both tables... any idea?? the number is the same for both tables... the only thing that changes is the field name in every table. please help, thank you.
select count(*) from dbo.temporal_announcements t inner join dbo.announcements a on t.user_unique_key = a.under_account where a.under_account = '07262007-020830'
Or perhaps you want the two counts of both tables summed up?
select sum(countt) from ( select count(*) as countt from dbo.temporal_announcements where user_unique_key = '07262007-020830' union select count(*) from dbo.announcements where under_account = '07262007-020830' ) t
This didn't solve the problem... I have 4 records (2 in each table) and the result display only 2... the first example didn't work... and the second one seems to work the first time only... but not anymore... here's the example...
select sum(countt) as valor from (select count(*) as countt from dbo.temporal_announcements where user_unique_key = '07262007-020830' union select count(*) as countt from dbo.announcements where under_account = '07262007-020830' ) t
select sum(countt) as valor from (select count(*) as countt from dbo.temporal_announcements where user_unique_key = '07262007-020830' union all select count(*) as countt from dbo.announcements where under_account = '07262007-020830' ) t
Thank you for all your support!!! -- you are the masters!! -- Well, i found another solution... in fact what we get are 2 numbers that we can easily sum...
after hours of looking to this problem I did the following... your last answer also works... here it is:
select (select count(*) from dbo.temporal_announcements where user_unique_key = '07262007-020830') + (select count(*) from dbo.announcements where under_account = '07262007-020830') as resultss