Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4111474
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T22:04:16+00:00 2026-05-20T22:04:16+00:00

I need to select the counts from two tables that share a common column

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T22:04:16+00:00Added an answer on May 20, 2026 at 10:04 pm

    You’re close. You want to join the two tables together before you do the aggregation

    select 
        clientid,
        sum(case when t.clientid is not null then 1 else 0 end ) as total1 
        sum(case when w.clientid is not null then 1 else 0 end ) as total1 
        from TFeed t FULL OUTER JOIN WFeed w 
        where w.dateadded = getdate() or t.dateadded = getdate()
    

    This might not be quite what you’re going for, but that’s the general idea. This also handles the case where there’s no data in one of the tables for a particular day.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working with an order system that has two tables Order and OrderLine
I have two msyql tables, Badges and Events. I use a join to find
I have two tables: **Product** ID Name SKU **Brand** ID Name Product table has
Two tables. emails id (int10) | ownership (int10) messages emailid (int10) indexed | message
I have two tables as follows: tblCountry (countryID, countryCode) tblProjectCountry(ProjectID, countryID) The tblCountry table
I have these 3 tables: EMPLOYEES Emp_id PK || First_Name || Last_Name || Hiring_Date
I have a page in one of my client's websites that generates an extensive
I'm finishing up my reports in my SQL Server 2008 Reporting Services project, and
I am using SQL 2005. Table one, LinkedDocumentFolderTable, contains the names and information about
I’m working on a small kind of log system to a webpage, and I’m

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.