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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T13:49:13+00:00 2026-06-03T13:49:13+00:00

Here it two table. Table1 SchoolID Teacher_name comm_yr 01 John 1990 02 Heley 1995

  • 0

Here it two table.

Table1
SchoolID   Teacher_name   comm_yr
01          John            1990
02          Heley           1995
03         George          1994
04          Chris           1998
05          Mary            1993

Table2
School_ID   Student_name
01        Heley
02        Chris
03        Chris
04        Mary
05        Heley

I would like to list the year each student has done as student and the year each student has done as teacher.

    SELECT Teacher_name, comm_yr As Teacher_comm_yr, comm_yr As Student_comm_yr
FROM Table1 INNER JOIN Table2
WHERE comm_yr (SELECT comm_yr As Teacher_comm_yr From Table1
Where teacher_name=student_name);

The Table is showing

Teacher_name    Teacher_comm_yr  Student_comm_yr
John                   1990 1990
Heley                 1995  1995
George                 1994 1994
Chris                  1998 1998
Mary                    1993    1993

But What I want is

Teacher_name    Teacher_comm_yr Student_comm_yr
John               1990 
Heley               1995     1990
George              1994    
Chris               1998      1995
Chris               1998     1994
Mary                1993     1998

But I could only execute the same year
Can you please help..

Thanks!

  • 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-03T13:49:13+00:00Added an answer on June 3, 2026 at 1:49 pm

    Some notes.

    SELECT 
      t1.Teacher_name, 
      t2.Student_name, 
      t1.comm_yr AS Teacher_comm_yr, 
      t1.comm_yr AS Student_comm_yr
    FROM Table1 AS t1 
    LEFT JOIN Table2 AS t2 
    ON t2.student_name = t1.teacher_name;
    

    I do not understand where Chris got 1995 from, based on your data.

    So how about:

    SELECT t.SchoolID,
           t.Teacher_name,
           t.comm_yr,
           q.SchoolID,
           q.Teacher_name,
           q.Student_name,
           q.comm_yr
    FROM   table11 t
           LEFT JOIN (SELECT a.SchoolID,
                             a.Teacher_name,
                             b.Student_name,
                             a.comm_yr
                      FROM   table11 AS a
                             INNER JOIN table22 AS b
                               ON a.SchoolID = b.School_ID) AS q
             ON t.Teacher_name = q.Student_name; 
    

    I have included more fields (columns) than necessary, to test the idea.

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

Sidebar

Related Questions

Alright so here are my two tables. CREATE TABLE [cards] ( [id] TEXT PRIMARY
First.. here are the two tables I've created (sans irrelevant columns).. CREATE TABLE users_history1
I have two tables: entitytype and project . Here are the create table statements:
I'm trying to join two table (call them table1 and table2) but only return
Let's say I have two Databases like so : DatabaseA create table Table1 (
I have two databases($db1, $db2) with exact table structure(table1). $db2.table1 has new rows which
Here are two tables: table1 cm_id cost 1 6.52 2 16.52 3 2.12 4
I have a bit of an architecture problem here. Say I have two tables,
I'm guessing this isn't possible, but here goes. I have two tables, and I'm
Here's two screen shots, showing the effect with a small viewport that has to

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.