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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T09:32:53+00:00 2026-05-25T09:32:53+00:00

Perhaps it will be an simple question but, I don’t know how to achieve

  • 0

Perhaps it will be an simple question but, I don’t know how to achieve it simply.
I have two tables mentioned below.

TableA

ID  Student1 Student2 Student1_Class Student2_Class
1    S0001   S0002      A              A
2    S0001   S0003      B              A

TableB

  Class StudentID StudentName
    A     S0001     Jack
    A     S0002     Adam
    A     S0003     Lily
    B     S0001     Simpson

I’m expecting to get a result something like

   ID  Student1  Name1  Student2  Name2  Student1_Class Student2_Class
    1    S0001   Jack    S0002   Adam      A              A
    2    S0001   Simpson S0003   Lily      B              A

How can I create a view based on these two tables to get the desired result?

  • 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-25T09:32:53+00:00Added an answer on May 25, 2026 at 9:32 am

    You have to JOIN on both Class and STudent becuase S0001 is repeated.

    However, your output is wrong because there is no A/S0001 match for ID = 2 in TableA to get “Simpson”. So assuming this is a typo, here you g0

    CREATE VIEW MyView
    AS
     SELECT
       A.ID,
       A.Student1,
       B1.StudentName as Name1,
       A.Student2,
       B2.StudentName as Name2,
       A.Student1_Class,
       A.Student2_Class
     from
       TableA as A
       INNER JOIN
       TableB as B1 ON A.Student1_Class = B1.Class AND A.StudentID = B1.Student2
       INNER JOIN 
       TableB as B2 ON A.Student2_Class = B2.Class AND A.StudentID = B2.Student1 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Perhaps this is a simple newbie C# question, but so be it---it will be
I have a feeling that this is a subjective question, but perhaps there's something
I feel like the answer to this question is probably very simple, but I'm
This is a very simple, probably too simple question but I'm afraid my limited
I'll try to keep my question simple: I have the following instance: MainClass mc
This seems like perhaps a naive question, but I got into a discussion with
I hardly know how to state this question, let alone search for answers. But
Sorry folks but I asked a question earlier and perhaps did not explain myself
My meta-question would be How do I ask this question intelligibly? but perhaps an
I'm creating a database with what I anticipate will be a long (perhaps several

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.