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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:32:20+00:00 2026-06-17T23:32:20+00:00

I am trying to figure out how to do many to many sql queries

  • 0

I am trying to figure out how to do many to many sql queries and have hit an issue.

My db structure is:

projects_users_roles: project_id, user_id, role_id
user_roles: id, name
projects: id, name, user_id

So in my query I would like to select all projects for user_id=23 and what role name they have been assigned on that project in projects_users_roles

I thought I had it but its returning FALSE

$query = "
SELECT p.name AS project_name
, r.name AS role_name
FROM projects AS p
JOIN projects_users_roles AS a
   ON a.project_id = p.id
JOIN users_roles AS role
   ON role.id = a.role_id WHERE a.user_id = 23
";
$result = mysql_query($query);
var_dump($result);
  • 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-17T23:32:21+00:00Added an answer on June 17, 2026 at 11:32 pm

    Could it be that the alias r is never defined? Your code sample shows r.name in the SELECT instead of role.name.

    $query = "
    SELECT p.name AS project_name
    , role.name AS role_name
    FROM projects AS p
    JOIN projects_users_roles AS a
       ON a.project_id = p.id
    JOIN users_roles AS role
       ON role.id = a.role_id WHERE a.user_id = 23
    ";
    $result = mysql_query($query);
    var_dump($result);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying to figure out why this PL/SQL purge script runs slowly
I was today trying to figure out on working with WebService and found many
I am trying to figure out how I can tell, in MATLAB, how many
trying to figure out why this is happening - I have an input text
I'm trying to figure out if this is relatively well-performing T-SQL (this is SQL
I'm trying to figure out how many times the maximum value of an array
Using SQL Server 2008, I am trying to figure out how to create a
I am trying to figure out how specific table is loaded in Microsoft SQL
Im trying to figure out how to build a view that contains (many of):
I'm sort of new to CakePHP and can't figure out how sql queries work

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.