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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T14:53:52+00:00 2026-06-02T14:53:52+00:00

I am trying to join 2 tables with a one to may relationship but

  • 0

I am trying to join 2 tables with a one to may relationship but I only want “the one” column data to appear in one row, it should be null in all all other rows (don’t care which ones). So:

TEACHER
---------
TeacherID
TeacherBiography
.
.
.

STUDENT
-----------
TeacherID
StudentFName
StudentLName
.
.
.

Example: You want to get all the students who’s First Name is ‘Joe’, join the Teacher using TeacherID, but limit the returned results so that the Teacher data is not returned in every row. The reason is because the TeacherBiography is large; I need it returned, but not in every row.

So some sample output should look like:

------------------------------------------------
StudentFName | StudentLName | TeacherID | TeacherBiography
------------------------------------------------
'Joe'        | 'Smith'      | 1         | 'long biography for teacher 1..'  
'Joe'        | 'Jones'      | 2         | 'long biography for teacher 2..'  
'Joe'        | 'Michaels'   | 1         | null
'Joe'        | 'Rogers'     | 3         | 'long biography for teacher 3..' 
'Joe'        | 'Washington' | 1         | null
.
.
.
.

So in the case of Michaels and Washington the TeacherBiograph (and all other teacher columns) is null because the data was already returned in the Smith row.

How do I do it?

-J

  • 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-02T14:53:53+00:00Added an answer on June 2, 2026 at 2:53 pm

    I think the only efficient way to do this is to Join STUDENTs and TEACHERs with the TeacherID as a key, then you can output this key only one time for only one row and the other rows for the same key output null instead, like this:

    var StudentsList = students.Join(  //Inner join
        Teachers,
        s => s.TeacherID,
        t => t.TeacherID,
        (teacher, teacherStudetns) => 
            new
            {
                Teacher = teacher,
                HisStudents = teacherStudetns
            });
    

    Then you can output only the key once, for example:

    foreach(var item in StudentsList)
    {
         Console.Writline("Teach Name: {0}, His students:", item.TeacherBiography);
         foreach(var student in item.HisStudents)
         {
             Console.writeLine("---------- {0}", student.StudentName);
         }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to join multiple tables, but one of the tables has multiple records
I have two tables that I am trying to join in a query, but
I am trying to join two tables in SQL, one containing a list of
I am trying to join two tables. One being the sys.databases table and the
I am trying to join two tables. The issue is one of the tables
Im trying to JOIN 2 tables and count the results. I have these tables;
I'm trying to join multiple tables together for building a report. The report lists
I am trying to join two tables; the purpose being able to search and
I have been trying to join two tables (USERS AND USERS_ROLES) based on their
I am currently using Symfony2 and Doctrine2 and am trying to join two tables

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.