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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T17:21:24+00:00 2026-06-06T17:21:24+00:00

I have a very weird thing to do and simply don’t know how. This

  • 0

I have a very weird thing to do and simply don’t know how. This is my table and its data:

+------+-----------+-------------+-------+------------+
| uid  | entity_id | entity_type | state | created    |
+------+-----------+-------------+-------+------------+
| 3913 |      1105 |           1 |     0 | 1340617072 |
| 3913 |      1105 |           1 |     1 | 1340617042 |
| 3913 |      3930 |           1 |     0 | 1340617071 |
| 3913 |      3930 |           1 |     1 | 1340617036 |
+------+-----------+-------------+-------+------------+

created holds the timestamp for which an action has been made, state is the state of the action (followed or unfollowed), uid is who makes the action and entity_id is the entity ID which is being followed/unfollowed.

I’m trying to do a query which gets me all the entity_id which the current user follows. First I was using:

SELECT entity_id FROM follow_objects WHERE uid=? AND entity_type=?

However I noticed that if I follow someone and then unfollow them, I still get a result for that person, because there are 2 entries for it (with state=1 and then state=0).

So I need to get the rows with the newest created column, which means the action is the most recent one. So I’ve tried:

SELECT entity_id FROM follow_objects WHERE uid=? AND entity_type=? group by entity_id HAVING created=MAX(created)

Which returns only rubbish data. I’m out of ideas. 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-06T17:21:26+00:00Added an answer on June 6, 2026 at 5:21 pm

    You need to select on a group-wise maximum. You must wrap the maximum in a subselect and join the table on itself where the entity_ids are equal and where the subselect’s max timestamp equals the created timestamp. The result is that you’ll get the top row data per entity_id group:

    SELECT
        a.entity_id,
        b.state,
        b.created
    FROM
        (
            SELECT entity_id, MAX(created) AS max_created
            FROM follow_objects
            WHERE uid = ? AND entity_type = ?
            GROUP BY entity_id
        ) a
    INNER JOIN
        follow_objects b ON
            a.entity_id = b.entity_id AND
            a.max_created = b.created
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So, I have this very weird error - Some advanced PHP devs might also
This is very weird. I have the following code: Assert.AreEqual(new DateTime(2000, 1, 1), DateTime.ParseExact(2000,
I have a very weird problem.. I really do hope someone has an answer
I have a very weird problem in Firefox ( version 3.5.2), and I am
I have a very weird problem with PROLOG. I have used it before, but
Hello I have a very weird problem in chrome I just cannot figure out!
I have encountered a very weird situation in Python. I have a while True:
I have just found something very weird while developing a website. While trying to
I have come across a very weird error. I'm on Solaris 10, using Ruby
Very often when you code you have a flag indicating two possibilities, like this:

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.