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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T04:00:17+00:00 2026-06-12T04:00:17+00:00

I have a SQL query where I want to join two tables to gether

  • 0

I have a SQL query where I want to join two tables to gether and then use that joined table to join a third table. I tried googling how to do this but it was awkward wording and found nothing useful. Here is the code I am trying to use:

SELECT t.id AS ID
, a.id AS ActivityID
, t.ProjectType AS ProjectType
, t.Tier1Mission AS Mission
, m.id ASMissionID
, m.name AS MissionName
, t.Tier2Activity AS Activity
, a.name AS ActivityName
, t.Tier3Project AS Project
FROM tActivity a
 INNER JOIN 
 (SELECT id, name FROM tMission) m
 ON tActivity.missionId = MissionID
 LEFT OUTER JOIN
 (SELECT *
  FROM tTaxonomy
  WHERE Tier1Mission = m.name AND Tier2Activity = a.name)

EDIT:
The main problem I’m running into is that the tActivity table has entries that have the same ‘name’ but refer to different MissionId’s. Joining all of the tables is easy but it needs to have the right MissionID, the relationship is held in the third table ‘tTaxonomy’.

  • 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-12T04:00:19+00:00Added an answer on June 12, 2026 at 4:00 am

    You almost have it, but need an alias and an ON clause for your second join insetad of the WHERE clause. Also, in your first ON clause, use the table alias a instead of the original name.

    SELECT t.id AS ID
    , a.id AS ActivityID
    , t.ProjectType AS ProjectType
    , t.Tier1Mission AS Mission
    , m.id ASMissionID
    , m.name AS MissionName
    , t.Tier2Activity AS Activity
    , a.name AS ActivityName
    , t.Tier3Project AS Project
    FROM 
      tActivity a
      INNER JOIN 
       (SELECT id, name FROM tMission) m
         ON a.missionId = m.id
      LEFT OUTER JOIN
       (SELECT *
         FROM tTaxonomy
       ) t ON t.Tier1Mission = m.name AND t.Tier2Activity = a.name
    

    However, looking over this, I see nothing requiring the use of joined subqueries. There are no aggregates or limits in the subqueries to necessitate them. You can just use plain table joins:

    SELECT t.id AS ID
    , a.id AS ActivityID
    , t.ProjectType AS ProjectType
    , t.Tier1Mission AS Mission
    , m.id ASMissionID
    , m.name AS MissionName
    , t.Tier2Activity AS Activity
    , a.name AS ActivityName
    , t.Tier3Project AS Project
    FROM
      tActivity a
      INNER JOIN tMission m ON a.missionId = m.id
      LEFT JOIN tTaxonomy t ON t.Tier1Mission = m.name AND t.Tier2Activity = a.name
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this SQL Query that pulls data from 3 tables. I am unable
I am using Access 2007 to create an SQL query to join two tables.
I have a SQL query that I'm currently solving by doing two queries. I
I have two tables that I join on the id-column, they look like: +-------+
I have two tables, Tasks and TaskMilestones. I want a query to return the
I want to LEFT JOIN two tables with the same column name. I have
I have the below query where I join two tables, the query is working
I have a fairly complex query in SQL that performs a count across two
I need help. I have a sql table t2 related to two other tables
I have the following sql query and I want to filter the results where

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.