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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:53:53+00:00 2026-05-27T14:53:53+00:00

This has stumped me for some time. My problem: I have 2 different tables..

  • 0

This has stumped me for some time.

My problem:
I have 2 different tables.. A table for user posts and a table for subscribers.

The subscribers table looks like this:

SubscriberID -> ProfileID
1 -> 2
1 -> 3
2 -> 3
2 -> 4
3 -> 2

My posts table looks like this:

PostID -> AuthorID -> PostDate -> PostBody
1 -> 2 -> 12/20/12 -> Hello Word
2 -> 3 -> 12/21/12 -> Bye Bye World
3 -> 1 -> 12/22/12 -> Oh Wait
4 -> 4 -> 12/23/12 -> Is anyone still here?

Basically, how it works is that the user with the ID is subscribed to the user with the ID 2 and 3. ID #2 is subscribed to ID #3 and #4. If a user is subscribed to a certain user, they can see only posts from the person they subscribed to. Now, I’m using the following I saw in a similar question:

SELECT POSTS.*
FROM POSTS
JOIN SUBSCRIBERS
ON POSTS.AUTHORID = SUBSCRIBERS.PROFILEID
WHERE SUBSCRIBERS.SUBSCRIBERID = ?
ORDER BY POSTS.POSTID DESC LIMIT 10

This works fine, but it does not show the user’s post as well. I’ve tried modifying it, but it’s not working :\

If you’re wondering, the “?” represents the user’s ID

So if you can, it would be great if someone could tell me how to include the user’s own posts alongside with the posts from the people the user subscribes to

  • 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-05-27T14:53:54+00:00Added an answer on May 27, 2026 at 2:53 pm

    You can do it modifying your query to :

    SELECT POSTS.*
    FROM POSTS
    LEFT JOIN SUBSCRIBERS
    ON POSTS.AUTHORID = SUBSCRIBERS.PROFILEID
    WHERE SUBSCRIBERS.SUBSCRIBERID = ? OR POSTS.AUTHORID = ?
    GROUP BY POSTS.POSTID ORDER BY POSTS.POSTID DESC LIMIT 10 
    

    It selects the user own posts as well. Hope this would help.

    Updated : Added GROUP BY POSTS.POSTID so duplicates are removed as you only look for data in POSTS table.

    When you run query like passing values- Eg. for user having id 1 the query looks like :

    SELECT POSTS.*
    FROM POSTS
    LEFT JOIN SUBSCRIBERS
    ON POSTS.AUTHORID = SUBSCRIBERS.PROFILEID
    WHERE SUBSCRIBERS.SUBSCRIBERID = 1 OR POSTS.AUTHORID = 1 GROUP BY POSTS.POSTID
    ORDER BY POSTS.POSTID DESC LIMIT 10
    

    Results are :

    PostID  AuthorID    PostDate    PostBody
    
    3       1   2012-12-21  Oh Wait
    2       3   2012-12-21  Bye Bye World
    1       2   2012-12-20  Hello Word
    

    This is what you get when pass values to the select query properly. The values passed to SUBSCRIBERID and AUTHORID should be same. The LEFT JOIN would fix your problem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This problem has got me stumped for a few days now. I have a
I have encountered a problem in my program that has me somewhat stumped. I
I have some code that does something like this (Irrelevant bits snipped): void foo(Bitmap
This one has be stumped. I'm doing some work on a legacy ASP.NET WebForms
I am stumped on this homework problem. I think I have the right answer
This one has me stumped. I'm using the for attribute on some links to
This one has me stumped. I found some code posted by Ray Burns to
Finding a good way to do this has stumped me for a while now:
This has me stumped. The follow code returns ,,,,,,: <script type=text/javascript> $(function() { $('#listB').sortable({
This really has my stumped today. I'm sure its simple, but... Here is my

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.