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 958709
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T00:54:36+00:00 2026-05-16T00:54:36+00:00

Im working myself into an SQL frenzy, hopefully someone out there can help! I’ve

  • 0

Im working myself into an SQL frenzy, hopefully someone out there can help!

I’ve got 2 tables which are basically Records and Outcomes, I want to join the 2 tables together, count the number of outcomes per record (0 or more) which I’ve got quite easily with:

Select records.Id, (IsNull(Count(outcomes.Id),0)) as outcomes
from records
Left Join
outcomes
on records.Id = outcomes.Id
group by
records.Id

The outcomes table also has a timestamp in it, what I want to do is include the last outcome in my result set, if I add that the my query it generates a record for every combination of records to outcomes.

Can any SQL expert point me in the right direction?

Cheers,

  • 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-16T00:54:37+00:00Added an answer on May 16, 2026 at 12:54 am

    try:

    SELECT
        dt.Id, dt.outcomes,MAX(o.YourTimestampColumn) AS LastOne
        FROM (SELECT --basically your original query, just indented differently
                  records.Id, (ISNULL(COUNT(outcomes.Id),0)) AS outcomes
                  from records
                      LEFT JOIN outcomes ON records.Id = outcomes.Id
                  GROUP BY records.Id
              ) dt
            INNER JOIN outcomes o ON dt.Id = o.Id
        GROUP BY dt.Id, dt.outcomes
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Got myself in a bit of a pickle here ... working on a CMS
I myself am convinced that in a project I'm working on signed integers are
After working with .NET's HttpWebRequest / Response objects, I'd rather shoot myself than use
I'm currently working on project with Haskell, and have found myself some trouble. I'm
I am working on a solo project, writing all code myself so no collaboration
Sorry if the question is confused, as I'm confused myself. I'm working around these
I'm working on a project which replaces a piece of paper, and on that
I often find myself in need of very complex SQL examples when testing abstraction
I'm currently working on a project where we have a large data warehouse which
Working with dates in ruby and rails on windows, I'm having problems with pre-epoch

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.