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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T15:01:01+00:00 2026-06-10T15:01:01+00:00

I am trying to join 3 tables together but I keep getting ‘unknown table

  • 0

I am trying to join 3 tables together but I keep getting ‘unknown table ‘calls’ in field list. I know the table ‘calls’ exists

This works…

$sql = "SELECT * FROM calls WHERE id = '$diary_id'";

but this doesn’t…

$sql = "SELECT * FROM (SELECT calls.id AS calls_id, calls.assigned_user_id AS assigned_user) calls
RIGHT JOIN accounts on accounts.parent_id = accounts.id
LEFT JOIN users on assigned_user = user.id
WHERE calls_id = '$diary_id'";

I am trying to use aliases because the tables I am trying to join have the same field names (an inherited database I have to use).

Any help will be greatly appreciated

  • 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-10T15:01:02+00:00Added an answer on June 10, 2026 at 3:01 pm

    Your subquery:

    SELECT calls.id AS calls_id, calls.assigned_user_id AS assigned_user
    

    is selecting calls.id and calls.assigned_user but there is no FROM clause from which the calls table/alias is defined. Add FROM calls to the subquery (although why use a subquery here at all?).

    You’re also referring to user.id in your join criterion, but the table is called users.

    And your join criterion for the accounts table, accounts.parent_id = accounts.id, looks very suspect: it appears that you’re trying to traverse hierarchical data that has been stored using the adjacency list model, but this join won’t accomplish that; indeed, MySQL doesn’t support recursive functions—so it is not well suited to this model at all. You might consider restructuring your data to use either nested sets or closure tables. See this answer for more information.

    Instead:

    SELECT *
    FROM   calls
      RIGHT JOIN accounts ON accounts.parent_id  = accounts.id -- is this right?
       LEFT JOIN users    ON calls.assigned_user = user.id
    WHERE calls.id = '$diary_id'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to join three tables together but having a problem getting the
I'm trying to join some tables together in MySQL, but I seem to get
i'm trying to join 3 tables together but use an IF statment to only
I'm trying to join two relatively simple tables together, but my query is experiencing
I'm trying to join multiple tables together but I'm having a bit of trouble
I'm trying to join some data together from 2 tables, but on several columns.
I am trying to join two tables together, but have an odd requirement. Normally
I'm trying to join multiple tables together for building a report. The report lists
I'm trying to LEFT JOIN two tables, to get a list of all rows
I have been trying to join 4 tables together so I can retrieve data

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.