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

  • Home
  • SEARCH
  • 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 8819653
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:24:55+00:00 2026-06-14T05:24:55+00:00

I have one table, Documents , that lists all documents and various information about

  • 0

I have one table, Documents, that lists all documents and various information about them. What I’m trying to do is, for a select group of authors, get a count of all documents they’ve authored in the past year. For each document, we have a column to store the Author name and ID.

I am currently getting what I want with the query below, but my problem is I also need to list all authors that haven’t authored any documents. (So, for the Number of Docs Signed column they’d have a zero value) Here’s what I have now:

SELECT 
[AuthorID] As "Author ID",
RTRIM([AuthorFirstName]) + ' ' + RTRIM([AuthorLastName]) AS "Author", 
COUNT(Document.ID) AS "Number of Docs Authored"

FROM Document

WHERE   [CompletedStatus] = 'Yes' 
AND     [AuthorID] IN (<list of author ID's>) 
AND     [CompletedOn] >= DATEADD(d, -365, getdate())


GROUP BY [AuthorID], [AuthorFirstName], [AuthorLastName]

ORDER BY [Number of Docs Signed] DESC

From reading around on SO I know I think I need some kind of subquery that I can join in order to show a ‘0’ when there are no rows returned by COUNT. But for the life of me I can’t figure out how to do it. I’m pretty sure it needs to be something like this.

  • 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-06-14T05:24:56+00:00Added an answer on June 14, 2026 at 5:24 am

    Start from the Authors table and do a left outer join to the documents table. This means you need to move the criteria into the outer join…

    SELECT 
    [AuthorID] As "Author ID",
    RTRIM([AuthorFirstName]) + ' ' + RTRIM([AuthorLastName]) AS "Author", 
    COUNT(Document.ID) AS "Number of Docs Authored"
    
    FROM 
        Author a
        LEFT OUTER JOIN Document d on d.AuthorID = a.ID
            AND [CompletedStatus] = 'Yes' 
            AND [CompletedOn] >= DATEADD(d, -365, getdate())
    WHERE
        a.ID IN (<list of author ID's>) 
    
    GROUP BY a.[ID], [AuthorFirstName], [AuthorLastName]
    
    ORDER BY [Number of Docs Signed] DESC
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have one table that has two fields - ID1 and ID2 ID1 can
I have one table that has sales records and another table that has additional
I have one table, e.g. pricerules, that have stored special prices by article for
hope this makes sense. I have merged together two tables one containing information about
I have two tables Table one is a list of documents documents: +-------------+---------------+ |
I have an application that uses hibernate. At one part I am trying to
I have looked throughout the greatest-n-per-group tag and found great information but nothing that
I have a table that records the name of uploaded documents, up to 14
I have a classified_id variable which matches one document in a MySql table. I
I have one table which contains events and dates, and another which contains the

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.