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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T11:27:43+00:00 2026-06-12T11:27:43+00:00

I had this SQL Query working perfectly. I made a few small changes to

  • 0

I had this SQL Query working perfectly. I made a few small changes to the database, and reran it and it simply stopped work.

My goal here is to join master_followups with followups_fb_messages.message_text but only return a single row for each UID in master_followups with the most RECENT followups_fb_messages.message_text joined to it.

SELECT master_followups.*, 
  followups_fb_messages.message_text, 
  followups_fb_messages.message_time 
FROM
  master_followups 
  LEFT JOIN followups_fb_messages 
    ON master_followups.UID = followups_fb_messages.FID 
    AND followups_fb_messages.message_time = 
      (SELECT
        MAX(followups_fb_messages.message_time) 
        FROM followups_fb_messages 
        WHERE  followups_fb_messages.FID = master_followups.UID
      )

I’ve been trying to figure out what happened for the last hour.

Instead of returning 100 results as expected, this is returning 340. I checked the database and it shows 100 rows in master_followups and 340 rows in followups_fb_messages.

I had this exact query working fine about an hour ago, then it stopped. Maybe I changed something, but I can’t see it.

  • 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-12T11:27:44+00:00Added an answer on June 12, 2026 at 11:27 am

    Let’s use some TDQD — Test-Driven Query Design.

    Time of most recent follow-up message for each ID

    SELECT FID, MAX(message_time) AS MostRecent
      FROM followups_fb_messages
     GROUP BY FID
    

    Most Recent Follow-up Message Information for each ID

    SELECT a.*
      FROM followups_fb_messages AS a
      JOIN (SELECT FID, MAX(message_time) AS MostRecent
              FROM followups_fb_messages
             GROUP BY FID
           ) AS b ON a.FID = b.FID AND a.message_time = b.MostRecent
    

    Note that this is a regular inner join, not an OUTER join.

    Master Follow-up Information and Follow-up Message Information

    SELECT m.*, f.message_text
      FROM master_followups AS m
      LEFT JOIN
           (SELECT a.FID, a.message_text
              FROM followups_fb_messages AS a
              JOIN (SELECT FID, MAX(message_time) AS MostRecent
                      FROM followups_fb_messages
                     GROUP BY FID
                   ) AS b ON a.FID = b.FID AND a.message_time = b.MostRecent
           ) AS f ON f.FID = m.UID
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working with SQL Server 2008 R2. I want to query a database
So I'm working on SQL Server 2008 and I have this query which should
I am having trouble with the following SQL statement. I have had this issue
I had asked this question Adding more attributes to LINQ to SQL entity Now,
Had this working; at one stage. The problem is the following text is now
I had this working at some point, as I had a question about this
I had this, which was working fine: public static Integer[] photos = new Integer[]
I have a SQL query running using something like this: PreparedStatement pstmt = dbConn.prepareStatement(sqlQuery);
i made a query for sql but it's really heavy and i really don't
Working with Entity framework and had a couple of questions on timeouts. This following

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.