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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T15:44:53+00:00 2026-05-15T15:44:53+00:00

I inherited an interesting table structure. This table structure looks like the following: GroupTable

  • 0

I inherited an interesting table structure. This table structure looks like the following:

GroupTable

  • ID
  • Name
  • Description

GroupItem

  • ID
  • GroupID
  • Name
  • CreatedBy
  • CreationDate

I need to get the three most recent GroupItem elements created by a specific user. The twist comes in with a requirement associated with the GroupID. The three GroupItem elements I retrieve must have at least one other GroupItem element with the same GroupID.

In other words, I am trying to retrieve the three most recent GroupTables that have at least two GroupItem elements where at least one of those GroupItem elements have been created by a specific user.

I have no clue how to accomplish this in SQL. I am using SQL Server 2008 and I keep coming up short.

  • 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-15T15:44:54+00:00Added an answer on May 15, 2026 at 3:44 pm

    As Tom H. was way faster in constructing the solution for your first definition I will do the second one 🙂

    SELECT TOP 3
        GT.ID
    FROM
        GroupTable GT
        INNER JOIN GroupItem GI1 ON GI1.GroupID = GT.ID
    WHERE
        GT.ID IN 
        (
        SELECT GroupID
        FROM
            GroupItem GI2
        WHERE
            GI2.ID = GT.ID AND
            GI2.CreatedBy = @user
        )
    GROUP BY 
        GT.ID
    HAVING 
        Count(*) >= 2
    ORDER BY
        MAX(GI1.CreationDate) DESC
    

    Main difference is that this query groups by GroupTable so there can be no case when the same table is returned more than once (which happens in Tom H. answer/is required in the first definition of the problem).

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

Sidebar

Related Questions

I inherited MYSQL database that has lots of tables with data like CREATE TABLE
I inherited the following code which is interesting . The logic seems either redundant
I inherited this gigantic legacy Java web app using Struts 1.2.4. I have a
I inherited this gigantic legacy Java web app using Struts 1.2.4. I have a
I have run into an interesting problem. I have inherited a database for daemon
I have found this thread which describes a very interesting OnSessionStart event, but I
I've noticed this interesting problem: function a() { this.aprop = 1; } function b()
So I have an interesting situation. I've inherited a big mess of code where
So, I'm following this article to customise the Html.EditorForModel template. Had it working -
Inherited properties and MetadataType does not seem to work with client side validation in

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.