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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T23:26:36+00:00 2026-05-19T23:26:36+00:00

I have several tables that I am joining that I need to add another

  • 0

I have several tables that I am joining that I need to add another table to and I can’t seem to get the right query. Here is what I have now –

Table 1
carid, catid, makeid, modelid, caryear

Table 2
makeid, makename

Table 3
modelid, modelname

Table 4
catid, catname

The query I am using to join these is:

SELECT * FROM table1 a
  JOIN table2 b on a.makeid=b.makeid
  JOIN table3 c on a.modelid=c.modelid
  JOIN table4 d on a.catid=d.catid
  WHERE a.carid = $carid;

Now I need to add a 5th table that I am getting from a 3rd party that I am having a hard time adding to my existing query. The new table has these fields –

Table 5
id, year, make, model, citympg, hwympg

I need the citympg and hwympg based on caryear from table 1, makename from table 2, and modelname from table 3. I know I can do a second query with those values, but I would prefer to do a single query and have all of the data in a single row. Can this be done in a single query? If so, how?

  • 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-19T23:26:37+00:00Added an answer on May 19, 2026 at 11:26 pm

    it’s possible to have more than condition in a join.
    does this work?

    SELECT a.*, e.citympg, e.hwympg
    FROM table1 a
      JOIN table2 b on a.makeid=b.makeid
      JOIN table3 c on a.modelid=c.modelid
      JOIN table4 d on a.catid=d.catid
      Join table5 e on b.makename = e.make
                    and c.modelname = e.model
                    and a.caryear = e.year
      WHERE a.carid = $carid;
    

    …though your question is not clear. Did you only want to join table5 to the others, or was there something else you wanted to do with table5?

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

Sidebar

Related Questions

I have several tables that get JOINed together to form a table with columns
Here's the setup: I have several tables that hold information for data objects which
I'm using Castle ActiveRecord in a warehouse project. I have several tables that get
I have several mysql databases and tables that need to be listened to. I
I have several tables that contain multipolygons. I need to find points within these
I have several tables in my database that have read-only fields that get set
I have several tables that need to be populated when I move my project
I have several tables that I am selecting data from. I am trying to
I have several tables that I want to put side by side, however when
I have several database tables that just contain a single column and very few

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.