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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T21:03:36+00:00 2026-06-14T21:03:36+00:00

I have a feed application that I am trying to group results from consecutively.

  • 0

I have a feed application that I am trying to group results from consecutively.
My table looks like this:

    postid | posttype | target | action     |        date         | title      | content
      1    |  userid  |  NULL  | upgrade    | 0000-01-00 00:00:00 | Upgraded 1 | exmple
      1    |  userid  |  NULL  | upgrade    | 0000-01-00 00:00:01 | Upgraded 2 | exmple
      1    |  userid  |  NULL  | downgrade  | 0000-01-00 00:00:02 | Downgraded | exmple
      1    |  userid  |  NULL  | upgrade    | 0000-01-00 00:00:03 | Upgraded   | exmple

What I would like the outcome to be is:

    postid | posttype | target | action     |        date         | title      | content
      1    |  userid  |  NULL  | upgrade    | 0000-01-00 00:00:01 | Upgrade 1  | exmple,exmple
      1    |  userid  |  NULL  | downgrade  | 0000-01-00 00:00:02 | Downgraded | exmple
      1    |  userid  |  NULL  | upgrade    | 0000-01-00 00:00:03 | Upgraded   | exmple

So as you can see because Upgrade 1 & Upgrade 2 were sent Consecutively, it groups them together. The “Action” table is a reference, and should be used for the consecutive grouping as well as the postid & posttype.

I looked around on SO but didnt see anything quite like mine. Thanks in advance for any help.

  • 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-14T21:03:37+00:00Added an answer on June 14, 2026 at 9:03 pm

    Here’s another version that works with MySQL Variables and doesn’t require 3 level nesting deep. The first one pre-sorts the records in order by postID and Date and assigns them a sequential number per group whenever any time a value changes in one of the Post ID, Type and/or action. From that, Its a simple group by… no comparing record version T to T2 to T3… what if you wanted 4 or 5 criteria… would you have to nest even more entries?, or just add 2 more @sql variables to the comparison test…

    Your call on which is more efficient…

    select
          PreQuery.postID,
          PreQuery.PostType,
          PreQuery.Target,
          PreQuery.Action,
          PreQuery.Title,
          min( PreQuery.Date ) as FirstActionDate,
          max( PreQuery.Date ) as LastActionDate,
          count(*) as ActionEntries,
          group_concat( PreQuery.content ) as Content
       from
          ( select
                  t.*,
                  @lastSeq := if( t.action = @lastAction
                              AND t.postID = @lastPostID
                              AND t.postType = @lastPostType, @lastSeq, @lastSeq +1 ) as ActionSeq,
                  @lastAction := t.action,
                  @lastPostID := t.postID,
                  @lastPostType := t.PostType
               from
                  t,
                  ( select @lastAction := ' ',
                           @lastPostID := 0,
                           @lastPostType := ' ',
                           @lastSeq := 0 ) sqlVars
               order by
                  t.postid,
                  t.date ) PreQuery
       group by
          PreQuery.postID,
          PreQuery.ActionSeq,
          PreQuery.PostType,
          PreQuery.Action    
    

    Here’s my link to SQLFiddle sample

    For the title, you might want to adjust the line…

    group_concat( distinct PreQuery.Title ) as Titles,

    At least this will give DISTINCT titles concatinated… much tougher to get let without nesting this entire query one more level by having the max query date and other elements to get the one title associated with that max date per all criteria.

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

Sidebar

Related Questions

I have an Objective C application that reads data from an RSS feed using
I have an application that needs to check a website feed every second. Sometimes
I have a php application that uses the google feed api to get the
I have a calendar feed (.ics) available from my application, but it's quite large
I have a feed that is populating a single text field in a table
I have a currently running PHP application that I want to add real-time feed
I have an application that reads an rss feed, parses the xml and adds
i have a web page that generates an rss feed dynamically. http://localhost/syn/atom.aspx This produces
I have an in-application service which allows me to feed it messages from various
I am trying to read an rss feed from my MVC application. The code

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.