MySql Reblog/Retweet -


i've incorporated reblog system in app i'm building having hard time figuring out logic retrieve posts and reblogs in same stream.

i have post_reblog pivot table store post_id , user_id - id of user reblogged post.

the following query retrieves posts, not reblogged post - original. can't figure out how retrieve both original post and reblogged post , share them in same stream.

select * posts status = 'published' or id in (select * (select post_id post_reblog ) subquery) 

my tables

posts     post_id (int)     user_id (int)     title   (varchar)     body    (text)  post_reblog     post_id (int)     user_id (int) 

the issue reblogged posts in query. when use or that, each row able appear once.
1 possible solution union:

select post_id, user_id 'original poster', user_id 'current poster', title, body posts status = 'published' union select p.post_id, p.user_id 'original poster', pr.user_id 'current poster', p.title, p.body post_reblog pr inner join posts p on p.post_id = pr.post_id p.status = 'published' 

note, union all, union all not remove duplicate rows. also, note difference in 2 queries 'current poster' republisher.


Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

serialization - Convert Any type in scala to Array[Byte] and back -

SonarQube Plugin for Jenkins does not find SonarQube Scanner executable -