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

  • Home
  • SEARCH
  • 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 6727879
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:06:09+00:00 2026-05-26T10:06:09+00:00

(SELECT posts.id FROM posts INNER JOIN discussions ON discussions.post_id = posts.id INNER JOIN companies

  • 0
(SELECT posts.id FROM posts 
INNER JOIN discussions ON discussions.post_id = posts.id 
INNER JOIN companies ON discussions.company_id = companies.id 
INNER JOIN subscriptions ON subscriptions.subscribable_id = companies.id AND subscriptions.subscribable_type = 'Company' 
INNER JOIN users ON subscriptions.user_id = users.id WHERE users.id = 6)

UNION 

(SELECT posts.id FROM posts 
INNER JOIN users users_2 ON posts.analyst_id = users_2.id 
INNER JOIN subscriptions ON subscriptions.subscribable_id = users_2.id AND subscriptions.subscribable_type = 'User'
INNER JOIN users ON subscriptions.user_id = users.id WHERE users.id = 6)

It should be obvious that the last join is the same in both queries.. Just not sure how to “or” together joins.

  • 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-26T10:06:10+00:00Added an answer on May 26, 2026 at 10:06 am

    Some joins seem redundant:

    • discussions could be joined to subscriptions directly on the company_id column;

    • posts could be joined to subscriptions directly on the analyst_id column;

    • the last join to users in either SELECT is unnecessary as no data is retrieved from that table and the filter (users.id = 6) could be re-applied to subscriptions.user_id.

    So, I would probably rewrite the query like this:

    SELECT p.id
    FROM posts p
      INNER JOIN discussions d ON d.post_id = p.id
      INNER JOIN subscription s
        ON s.subscribable_type = 'Company' AND s.subscribable_id = d.company_id
        OR s.subscribable_type = 'User'    AND s.subscribable_id = p.analyst_id
    WHERE s.user_id = 6
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I tried this select posts.id, posts.title from posts inner join ( select post_id,max(created) from
I'm trying this: $result = mysql_query( SELECT Users.*, Posts.* FROM Users INNER JOIN Posts
The sql statement is like this: select posts.id, posts.title from posts inner join (select
i have users table and i have posts table i want select from users
SELECT * FROM wp_posts INNER JOIN wp_term_relationships ON ( wp_posts.ID = wp_term_relationships.object_id) INNER JOIN
I need to do a query like this: SELECT wposts.ID FROM posts wposts WHERE
if (isset($_POST['login'])) { $query = mysql_query(" SELECT id FROM users WHERE username = '".mysql_real_escape_string($_POST['username'])."'
Here's what I want to accomplish: Select all rows from table posts while also
SELECT p.id, p.title, p.uri, 'post' AS search_type FROM `posts` AS p WHERE title LIKE
SELECT DISTINCT wposts.* FROM wp_2_posts wposts, wp_2_postmeta wpostmeta, wp_2_postmeta wpostmeta1, wp_2_term_taxonomy, wp_2_terms, wp_2_term_relationships WHERE

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.