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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T14:38:47+00:00 2026-06-06T14:38:47+00:00

I have been trying to join two tables (USERS AND USERS_ROLES) based on their

  • 0

I have been trying to join two tables (USERS AND USERS_ROLES) based on their role id I put the left join on following query

users.id = users_roles.fk_user_id
but the output is not correct of users_roles.fk_role_id coulmun and shows NULL where it should display the id of users.id = users_roles.fk_user_id that is 4 (at most places) because on users.id = users_roles.fk_user_id the value of users_roles.fk_role_id = 4

Kindly let me know how can i fix that so my query should result the exact vlaues of ids where they match,
Thanks

SELECT users.id, users.v_first_name, users.v_last_name, user_facility.fk_facility_id,users.fk_tenant_id, marital_status.v_marital_status, 
            users.v_blood_type, NOW(),users_roles.fk_role_id
            FROM users
            LEFT JOIN (user_facility, marital_status, users_roles) ON
            users.id = user_facility.fk_user_id AND users.fk_marital_status_id=marital_status.id AND  users.id = users_roles.fk_user_id
  • 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-06T14:38:48+00:00Added an answer on June 6, 2026 at 2:38 pm

    well it is what you get by first implicitly inner-joining 3 tables and then explicitly left-joining the result to a 4th table only if 3 conditions relevant to all of the 3 inner-joinded tables are matched (i.e. when 3rd condition is false, nothing is joined from either of the 2 remaining tables)

    i strongly suggest not to combine implicit and explicit joins, i personally use explicit joins all the time:

    if you need an outer join:

    SELECT ...
    FROM users
    LEFT JOIN user_facility ON users.id = user_facility.fk_user_id
    LEFT JOIN marital_status ON users.fk_marital_status_id=marital_status.id
    LEFT JOIN users_roles ON users.id = users_roles.fk_user_id
    

    if you need an inner join:

    SELECT ...
    FROM users
    JOIN user_facility ON users.id = user_facility.fk_user_id
    JOIN marital_status ON users.fk_marital_status_id=marital_status.id
    JOIN users_roles ON users.id = users_roles.fk_user_id
    

    or if you prefere implicit inner joins for some obscure reason:

    SELECT ...
    FROM users,
         user_facility,
         marital_status,
         users_roles
    WHERE users.id = user_facility.fk_user_id
      AND users.fk_marital_status_id=marital_status.id
      AND users.id = users_roles.fk_user_id
    

    (implicit outer joins are getting deprecated in all RDBMS as far as i know)

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

Sidebar

Related Questions

I'm trying to join two relatively simple tables together, but my query is experiencing
I'm trying to join two SQL tables, parent (which I have complete design control
I've been trying to perform a join on two tables in MySQL, and the
I have been trying to find out why the following lines of code do
I'm trying to write a query for a database that will left join a
I have a mysql database with two tables, bookings and users. They are linked
I am using Zend Framework and have been trying to do a joined query
I have 3 tables. One for users, one for posts, and a join table
Have have been trying to make a validator for my xml files. I have
I have been trying very hard to achieve rounded corners with IE6+jquery ui tabs.

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.