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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T07:36:28+00:00 2026-06-10T07:36:28+00:00

I’m developing a little rss feed emailer. The four tables i have are Users,

  • 0

I’m developing a little rss feed emailer.

The four tables i have are Users, Feeds, Subscriptions, and Distribution. Feeds contain the actual feed details, Subscriptions connect the Users with the Feeds, and Distribution records the emails transactions of the rss feed posts.

I’m trying to query the Distribution table to get the latest record for each user/feed subscription. I have the following query but it obviously only returns one row. I need to use a subquery but I can’t wrap my head around how.

SELECT d.id, d.user_id, d.feed_id, d.created
FROM Distribution AS d
INNER JOIN Feeds AS f ON f.id = d.feed_id
INNER JOIN Subscriptions AS s ON s.feed_id = d.feed_id
GROUP BY d.id, d.user_id, d.feed_id
ORDER BY d.created DESC 
LIMIT 1

Distribution table data
id, created, feed_id, post_id, user_id, success

(0, '2012-08-31 09:37:49', 20, 3, 2, 1)
(1, '2012-08-25 09:36:21', 20, 1, 1, 1)
(2, '2012-08-25 09:37:49', 21, 1, 2, 1)
(4, '2012-08-25 09:39:06', 21, 4, 1, 1)
(5, '2012-08-25 10:12:29', 20, 7, 2, 0)
(6, '2011-05-24 10:34:30', 20, 112, 1, 0)

the following query produces the following results

SELECT Distribution.*
FROM   Distribution NATURAL JOIN (
  SELECT   user_id, feed_id, MAX(created) AS created
  FROM     Distribution
  GROUP BY user_id, feed_id
) t

(0, '2012-08-31 09:37:49', 20, 3, 2, 1)
(1, '2012-08-25 09:36:21', 20, 1, 1, 1)
(2, '2012-08-25 09:37:49', 21, 1, 2, 1)
(4, '2012-08-25 09:39:06', 21, 4, 1, 1)
  • 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-10T07:36:30+00:00Added an answer on June 10, 2026 at 7:36 am

    As explained in the MySQL manual:

    The server is free to choose any value from each group, so unless they are the same, the values chosen are indeterminate. Furthermore, the selection of values from each group cannot be influenced by adding an ORDER BY clause. Sorting of the result set occurs after values have been chosen, and ORDER BY does not affect which values the server chooses.

    You are trying to find the groupwise maximum, which requires use of a subquery to identify the latest record.

    The subquery itself should use MySQL’s MAX() function on the created column to identify the corresponding value of most recent record within each group, then use that information to join against the table in the outer/parent query. I think this is what you’re after, but it’s hard to be certain without your table schema/sample data (at very least it should set you on the right path):

    SELECT Distribution.*
    FROM   Distribution NATURAL JOIN (
      SELECT   user_id, feed_id, MAX(created) AS created
      FROM     Distribution
      GROUP BY user_id, feed_id
    ) t
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I am trying to understand how to use SyndicationItem to display feed which is
I have a jquery bug and I've been looking for hours now, I can't
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into

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.