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
I think the only efficient way to do this is to Join
STUDENTs andTEACHERs with theTeacherIDas a key, then you can output this key only one time for only one row and the other rows for the same key outputnullinstead, like this:Then you can output only the key once, for example: