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

The Archive Base Latest Questions

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

My query pulls results from several tables using a few LEFT JOIN s. It

  • 0

My query pulls results from several tables using a few LEFT JOINs. It currently works fine. However, I now have to get two different fields from the same table column (but matching different conditions). I don’t know how to make sure the correct column alias gets assigned from the correct LEFT JOIN. Make sense?

So here’s for example…

SELECT table1.user_id, table2.value AS school, table2.value AS language  FROM table1  
LEFT JOIN table2 ON table2.user_id = table1.user_id AND table2.key = 'school'
LEFT JOIN table2 ON table2.user_id = table1.user_id AND table2.key = 'language'

I need the column aliases with the corresponding JOIN. How do I do this?

For reference, here is my original query (without secondary JOIN):

SELECT wsat_ib.user_id, wpjb_resume.id resume_id, wpjb_resume.firstname, wpjb_resume.lastname, 
     wsat_ib.overall_score, wsat_ib.account_score, wsat_ib.econ_score, wsat_ib.math_score,
     wsat_ib.logic_score, wsat_ib.fsanaly_score, wsat_ib.corpval_score, wsat_ib.end_time, 
     GROUP_CONCAT(DISTINCT wp_usermeta.meta_value) AS target_employers, wpjb_field_value.value AS school, 
     GROUP_CONCAT(wpjb_application.job_id) AS applications FROM  `wsat_ib` 
    LEFT JOIN wp_usermeta ON wsat_ib.user_id = wp_usermeta.user_id
    LEFT JOIN wpjb_resume ON wsat_ib.user_id = wpjb_resume.user_id
    LEFT JOIN wpjb_field_value ON wpjb_resume.id=wpjb_field_value.job_id AND wpjb_field_value.field_id=3
    LEFT JOIN wpjb_application ON wpjb_application.user_id = wsat_ib.user_id 
    WHERE (wp_usermeta.meta_key = 'target_employer' AND (wp_usermeta.meta_value = 'public' OR wp_usermeta.meta_value=1523) AND wpjb_resume.is_active =1) AND (wpjb_resume.firstname='Xu' OR wpjb_resume.lastname='Xu') 
    GROUP BY wsat_ib.user_id, resume_id, wpjb_resume.firstname, wpjb_resume.lastname, wsat_ib.overall_score, wsat_ib.account_score, wsat_ib.econ_score, wsat_ib.math_score, wsat_ib.logic_score, wsat_ib.fsanaly_score, wsat_ib.corpval_score, wsat_ib.end_time, wpjb_field_value.value
     ORDER BY overall_score DESC LIMIT 0, 20;

Here’s my early attempt at implementing the solutions below. I’ve added the AS school to the JOIN clause, but have not yet added the second JOIN for that table. For some reason, this version returns no results.

SELECT wsat_ib.user_id, wpjb_resume.id resume_id, wpjb_resume.firstname, wpjb_resume.lastname, 
 wsat_ib.overall_score, wsat_ib.account_score, wsat_ib.econ_score, wsat_ib.math_score,
 wsat_ib.logic_score, wsat_ib.fsanaly_score, wsat_ib.corpval_score, wsat_ib.end_time, 
 GROUP_CONCAT(DISTINCT wp_usermeta.meta_value) AS target_employers, wpjb_field_value.value AS school, 
 GROUP_CONCAT(wpjb_application.job_id) AS applications FROM  `wsat_ib` 
LEFT JOIN wp_usermeta ON wsat_ib.user_id = wp_usermeta.user_id
LEFT JOIN wpjb_resume ON wsat_ib.user_id = wpjb_resume.user_id
LEFT JOIN wpjb_field_value AS school ON wpjb_resume.id=wpjb_field_value.job_id AND wpjb_field_value.field_id=3
LEFT JOIN wpjb_application ON wpjb_application.user_id = wsat_ib.user_id 
WHERE (wp_usermeta.meta_key = 'target_employer' AND (wp_usermeta.meta_value = 'public' OR wp_usermeta.meta_value=1523) AND wpjb_resume.is_active =1) AND (wpjb_resume.firstname='Xu' OR wpjb_resume.lastname='Xu') 
GROUP BY wsat_ib.user_id, resume_id, wpjb_resume.firstname, wpjb_resume.lastname, wsat_ib.overall_score, wsat_ib.account_score, wsat_ib.econ_score, wsat_ib.math_score, wsat_ib.logic_score, wsat_ib.fsanaly_score, wsat_ib.corpval_score, wsat_ib.end_time, wpjb_field_value.value
 ORDER BY overall_score DESC LIMIT 0, 20;
  • 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-17T03:34:39+00:00Added an answer on June 17, 2026 at 3:34 am

    You need to alias the tables as well, not just the columns.

    SELECT table1.user_id, schools.value AS school, languages.value AS language
    FROM table1  
    LEFT JOIN table2 AS schools ON schools.user_id = table1.user_id
        AND schools.key = 'school'
    LEFT JOIN table2 AS languages ON languages.user_id = table1.user_id
        AND languages.key = 'language'
    

    If a table appears more than once in a query, you can think of each appearance kind of as an instance. You need to name each instance of the table to disambiguate them.

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

Sidebar

Related Questions

I have a query that is supposed to pull records from several tables using
I have this SQL Query that pulls data from 3 tables. I am unable
I am running oracle and have a query which pulls some results from the
I have a query that pulls values from multiple tables. I want to order
Hi I have a query that pulls the results from a search but I
I am trying to write a SQL query that pulls from 3 tables and
I have a query which pulls a count from a DB by searching by
I have a LINQ to ENTITY query that pulls from a table, but I
I have the following query. It works just fine but I need to pull
I have a MySQL query in PHP that pulls back two columns of results

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.