0

I can't figure out how I would select data for the record with the newest social.id aka sid while grouping by t1.id. I have tried making a select in select, ordering, grouping by t1.id having social.id = max(social.id) but it didn't work(returns 0 values). How would I do this?

posts contains post info while social contains the number of likes for posts. I want to get the social record with the highest social.id for the t1.id = socail.post_id to get the most accurate data. How should I do this?

SELECT posts.id, posts.reply, social.id As sid FROM posts
LEFT JOIN user on posts.user_id = user.id
LEFT JOIN social ON posts.id = social.post_id
WHERE posts.reply = 22
GROUP BY posts.id
ORDER BY posts.time
LIMIT 12 OFFSET 0
Bill Karwin
  • 499,602
  • 82
  • 638
  • 795

0 Answers0