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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:42:31+00:00 2026-05-26T05:42:31+00:00

I’m trying to get a MySQL query to give me related data 2 tables

  • 0

I’m trying to get a MySQL query to give me related data 2 tables away. So one user would have access to 2 projects, with a total of 3 posts (in “stream”). Essentially, I want to get the associated projects in project_users and then get posts in stream associated those projects.

The data looks something like this:

Table 1: user (1 user identified by ‘id’)

Table 2: project_users (user associated with 2 projects in this case)

Table 3: stream (posts attached to different projects, but I should get 3 based on my test data set)

My (broken) query looks like this:

SELECT U.`id`, P.`kf_users`, P.`kf_projects`, S.`kf_projects`, S.`body`
    FROM users U
    LEFT JOIN projects_users P ON U.`id` = P.`kf_users`
    LEFT JOIN stream S ON P.`kf_users` = S.`kf_projects`
    WHERE U.`id` = 1

What on earth am I missing? I tried subqueries, but it wouldn’t let me have multiple rows in it, rendering it useless in the form I had it.

Thanks!

  • 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-26T05:42:31+00:00Added an answer on May 26, 2026 at 5:42 am

    I get no results any time I try this query

    Really?! Then try changing it to this:

    SELECT *
    FROM users U
    WHERE id = 1
    

    I suspect that will give you no results too. Knowing that this query also fails should hopefully help you to find the problem more quickly (you don’t have a user with id 1).

    Note: If this gives you a result, then the query you posted above with the LEFT JOIN should return some rows too, because adding a LEFT JOIN shouldn’t remove any rows.


    Update: Try adding aliases to make the column names unique:

    SELECT
        U.id,
        P.kf_users,
        P.kf_projects AS p_kf_projects,
        S.kf_projects AS s_kf_projects,
        S.body
    FROM ....
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am trying to loop through a bunch of documents I have to put
I have some data like this: 1 2 3 4 5 9 2 6
Basically, what I'm trying to create is a page of div tags, each has
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I would like to count the length of a string with PHP. The string
this is what i have right now Drawing an RSS feed into the php,
I am reading a book about Javascript and jQuery and using one of the

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.