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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:08:04+00:00 2026-06-09T13:08:04+00:00

I have a join that selects all of the posts from users I am

  • 0

I have a join that selects all of the posts from users I am following and friends with

SELECT  * 
FROM    posts a 
LEFT JOIN relationships b
ON a.user_id = b.user_2 
WHERE   b.user_1 = $user_id AND 
 b.status IN (1,3,4)

How can I get this query to also select all of the posts where a.user_id = $user_id (my id)?
Basically, also select all of the posts from me? Without duplicating any data.

  • 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-09T13:08:06+00:00Added an answer on June 9, 2026 at 1:08 pm

    If you basically want the results of 2 queries in one table use a union query. You would need to fix the WHERE clause in the 2nd query to be correct but what about something like

    SELECT  *
    FROM    posts a
    LEFT JOIN relationships b
    ON a.user_id = b.user_2
    WHERE   b.user_1 = $user_id AND
     b.status IN (1,3,4)
    UNION DISTINCT
    SELECT *
    FROM    posts a
    WHERE   a.user_id = $user_id (my id)
    

    I would also question your use of a left join – I would think that an INNER JOIN would be better

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

Sidebar

Related Questions

I have a query that returns all stream posts from users (with comments): SELECT
I have the following query: 'SELECT * FROM posts LEFT JOIN taxi ON taxi.taxiID
I have the following query with many LEFT JOIN clauses that has 7 result
I have a quite complex multi-join TSQL SELECT query that runs for about 8
I have this query that should display all posts related to a specific tag
The following query selects all posts and each post's owner, all of the comments
I have a basic MySQL query: $getFeed = SELECT posts.postID, posts.postTitle, ..... FROM posts
I have the following tables for my CakePHP app that allows friendships between users:
I have 3 tables. One for users, one for posts, and a join table
I have a join which deletes rows that match another table but the joining

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.