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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:26:27+00:00 2026-05-27T01:26:27+00:00

I’m trying to write an SQL query that will gather certain data in one

  • 0

I’m trying to write an SQL query that will gather certain data in one table, based on data across several other tables. That part was easy enough. Unfortunately, I also need to recover data from a second table, and that needs to be done with a left join.

If I just do a left join, e. g.

select *
from table_A A
left join table_B B on A.id=B.id

everything is fine. I can add in a where clause safely enough, like

where A.id>5

The issue occurs when I try to have more than one table on the left hand side, for example

select *
from table_A, table_C
left join table_B on A.id=B.id
where table_A.id=table_C.id

All of a sudden, A.id is no longer a recognized column. I tried changing it so that I have select A.id as foo, and then do on foo=B.id, but foo isn’t recognized either. ( Unknown column ‘bla’ in ‘on clause’)

While there are many references out there than explain how to do a join clause, and some examples even use a simple where clause, I can’t find any that combine a join clause, a where clause, and multiple tables on the left hand side.

For background on the question:

My original query was:

select SQL_CALC_FOUND_ROWS tutor_user.username
    , tutor_user.userid
    , tutor_tutor.rate
    , tutor_user.username 
from tutor_user
    , tutor_attends
    , tutor_tutors_in
    , tutor_subject
    , tutor_tutor 
where tutor_user.userid=tutor_attends.userid 
    and tutor_attends.schoolid=80 
    and tutor_tutors_in.userid=tutor_user.userid 
    and tutor_tutors_in.subjectid=tutor_subject.subjectID 
    and tutor_subject.name='Aerospace Studies' 
    and tutor_tutor.userid=tutor_user.userid //ERROR
LIMIT 0, 15

Unfortunately, there’s no guarantee that tutor_tutor information will exist for every user — a minor flaw that’s persisting from poor decisions early on in the website/database design cycle. So, the easy solution is to turn it into a join.

The problem is, I can’t find any good tutorials explaining how to combine a join with where clauses. My best effort comes up with the following:

select SQL_CALC_FOUND_ROWS tutor_user.username
    , tutor_user.userid
    , tutor_tutor.rate
    , tutor_user.username 
from tutor_user
    , tutor_attends
    , tutor_tutors_in
    , tutor_subject
LEFT JOIN tutor_tutor
    on tutor_user.userid=tutor_tutor.userid
where tutor_user.userid=tutor_attends.userid 
    and tutor_attends.schoolid=80 
    and tutor_tutors_in.userid=tutor_user.userid 
    and tutor_tutors_in.subjectid=tutor_subject.subjectID 
    and tutor_subject.name='Aerospace Studies' 
    LIMIT 0, 15
  • 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-27T01:26:28+00:00Added an answer on May 27, 2026 at 1:26 am

    Ideally, you shouldn’t mix the lazy join syntax (select ... from a,b,c) with the more specific select ... from a join B ... join c .... And doing a select * can be problematic as well, especially you’re not going to be using all of the fields, or need to refer to the fields by name instead of position.

    So your query should be:

    SELECT A.field, A.otherfield, B.field, B.otherfield, C.yetanotherfield
    FROM table_A AS A
    JOIN table_B as B on A.id = B.a_id
    JOIN table_C as C on B.id = C.b_id
    WHERE ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into

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.