tables:
POSTS
(id
title
data
userid)
CONNECTIONS(
postid
userid)
I want to get rows from the POSTS table by the amount of c.postid values that are the same in the CONENCTIONS c table
In easier terms, I want to get the most popular posts, with the most connections.
I hope that makes sense.
A little warning:
It would be pretty heavy query in case if you dealing with high loads. I’d suggest to have the
cnt(a number of connections) field right within yourpoststable (it would be a denormalization and it’s harder to maintain, but would work good enough to decrease querying time by 2 times or more if you would create anindexoncntfield).Let me know if the query has worked or not, cause I can’t check myself right now.