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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T05:49:37+00:00 2026-06-17T05:49:37+00:00

Table join : |ID|admin|user |data| |1 |00001|00002|XXXX| admin (fk) = users.id , user (fk)

  • 0

Table join:

|ID|admin|user |data|
|1 |00001|00002|XXXX|
  • admin(fk) = users.id,
  • user(fk) = users.id.

Table users:

|id   |name|pass|type |
|00001|root|1234|admin|
|00002|user|1235|user |

select join.*,users.name as admin,users.name as user from join 
left join users on users.id=join.admin
left join users on users.id=join.user

where grrrrrrr

How can I do this?

Original query, I’m trying to run:

SELECT

    visits.id,
    visits.patient AS patient_id,
    visits.doctor AS doctor_id,
    visits.date,
    visits.time_booked,
    visits.time_arrived,
    visits.time_start,
    visits.time_end,
    visits.type_id,
    visits.complain,
    visits.diagnosis,
    visits.note,
    visits.stats,
    (personal.name WHERE personal.id=visits.patient and personal.role='patient') AS pt_name,
    (personal.name WHERE personal.id=visits.doctor and personal.role='doctor') AS dr_name
    FROM
    visits ,
    personal
  • 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-17T05:49:39+00:00Added an answer on June 17, 2026 at 5:49 am

    You have to alias the table users with different aliases. Something like

    select 
      a.*,
      u1.name as admin,
      u2.name as user 
    from `join` a 
    left join users u1 on u1.id = a.admin
    left join users u2 on u2.id = a.`user`;
    

    Also you have to escape the table name join, user since they are reserved keywords in MySQL. Try to avoid those names as object names.

    SQL Fiddle Demo

    This will give you:

    | ID | ADMIN | USER | DATA |
    ----------------------------
    |  1 |     1 |    2 | XXXX |
    

    Update

    For your query after you updated your question, you have to do this the same way, like this:

    SELECT
      v.id,
      v.patient AS patient_id,
      v.doctor AS doctor_id,
      v.date,
      v.time_booked,
      v.time_arrived,
      v.time_start,
      v.time_end,
      v.type_id,
      v.complain,
      v.diagnosis,
      v.note,
      v.stats,
      pationts.name AS pt_name,
      doctors.name AS dr_name
    FROM visits v
    LEFT JOIN personal pationts  ON pationts.id   = v.patient 
                                AND pationts.role ='patient'
    LEFT JOIN personal doctors   ON doctors.id    = v.patient 
                                AND doctors.role  ='doctor';
    

    Updated SQL Fiddle Demo

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

Sidebar

Related Questions

I have three tables: Users, Groups and GroupsUsers User table: id: 1 username: admin
I want to join table Documents(id, name) and Tags(tagId, tagname, docId(FK)). However result will
If i have two tables like user table-u userid | name 1 | lenova
How would I join Table 1 and 2 together? Table 1: SELECT Roomid, Room,
A legacy database contains a join table which links tables table1 and table2, and
I have a primary table for Articles that is linked by a join table
I am wondering how to build a join table articles_categories, but one where there
I'm trying to create a record within a join table from the action of
I'm trying to create a record within a join table from the action of
I have two tables (Table A, Table B) joined with a join table (TableAB)

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.