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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T14:22:47+00:00 2026-06-18T14:22:47+00:00

Having got an excellent answer to my last question: Improving Efficiency of my SQL

  • 0

Having got an excellent answer to my last question: Improving Efficiency of my SQL (thanks @Bohemian) I have now realised I was a little short-sighted as there is an added complication.

Using the same table LIKES (likeID,userID,objectID,likeDate) the idea is that a person earns 1 point each time someone likes an object after they have liked it.

With the help from the previous question I can get the number of likes after a users like but now I need to consider that there are objects in this problem.

I want to be able to calculate the number of points a user is entitled to by counting the likes made after theirs for each object they liked (oooh that was a messy sentence).

I am considering a further “nesting” of SQL but this is out of my league and so I can’t really offer any code other than what’s in the last question.

  • 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-18T14:22:49+00:00Added an answer on June 18, 2026 at 2:22 pm

    You can do this with a correlated subquery:

    select l.userid, l.objectid, l.LikeDate,
           (select count(*) from likes l2 where l2.objectid = l.objectid and l2.LikeDate >= l.likeDate and l2.userid <> l.userid
           ) as NumLikesAfterward
    from likes l
    

    What this is doing is counting the number of likes on an object, by other users, after a given like. It returns one row for every row in likes. The calculation is done using a correlated subquery in the select clause.

    It will run much faster assuming you have an index on likes(objectid, likedate, userid).

    To get the total points for a user:

    select sum(NumLikesAfterward) as TotalPoints
    from (select l.userid, l.objectid, l.LikeDate,
                 (select count(*) from likes l2 where l2.objectid = l.objectid and l2.LikeDate >= l.likeDate and l2.userid <> l.userid
                 ) as NumLikesAfterward
          from likes l
          where userid = $userid
         ) uol
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having a trouble: I've got a GlassFish Server configured in Eclipse. Now, I
I'm having some problems building an hierarchistic array structure - I have almost got
After a sking this question , I still have a question. I got both
I have got a program having an array of buttons, each of these button
OK, so having just got the key to be accepted and have an encrypted
I got an entity E having a many-to-many relation with entity F. Now i
I'm having such a problem: got dataset with a table(s). Say, we have already
I got a little ruby app going and I'm having trouble with one part.
I've just got myself into a little mess and am having trouble thinking myself
I am having fun with WPF and got a problem. I have googled and

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.