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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T21:13:12+00:00 2026-05-12T21:13:12+00:00

I have a simple table containing Student Numbers and corresponding Teacher Numbers, and I

  • 0

I have a simple table containing Student Numbers and corresponding Teacher Numbers, and I need to denormalize it for input to a legacy system.

For example, here’s what the data looks like now:


StudNumber  TeacherNumber
445        57315
445        88584
445        95842
858        88115
858        65443
858        57315
858        21144
858        18657
858        88584
311        64521
665        35512
665        57315
665        15546

What I'd like it to look like is this, splitting out each Teacher into a separate column, filling columns from left-to-right. One business rule is that each student can have no more than six teachers:


StudNum Teacher1    Teacher2    Teacher3    Teacher4    Teacher5    Teacher6
445     57315       88584        95842
858     88115       65443        57315      21144        18657      88584
311     64521
665     35512       57315        15546

There are 10,000+ rows in the original table, so I need to do this programatically.
Thank you!

  • 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-12T21:13:13+00:00Added an answer on May 12, 2026 at 9:13 pm

    You can use pivot. You also need to “Rank” your teachers 1-6. See my comment on how you want to do this. For now:

    Select StudNumber, TeacherNumber, TeacherRank
    from (
       Select ST.StudNumber
           , ST.TeacherNumber
           , ROW_NUMBER() OVER (PARTITION BY ST.StudNumber 
                        ORDER BY ST.TeacherNumber) AS TeacherRank
       From StudentTeacher AS ST)
    Where TeacherRank <=6
    

    Then you can pivot on this statement. Here is a good explanation: Using Pivot and UnPivot

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

Sidebar

Related Questions

Im making a simple score keeping system and each user can have stats for
I have this simple piece of code on a windows form containing said DataGridView
I have a WPF database viewer application: It's a simple main window containing a
I have a simple blog with posts and tags. I want to add email
I'm new to programming so forgive my simple questions. Basically, I have two different
I'm using AbstractTransactionalJUnit4SpringContextTests to run a simple test: public class MyTests extends AbstractTransactionalJUnit4SpringContextTests {
Figuring out a title for this question was hard, but the following is harder
It's crazy, but query performance is about 50% WORSE after I add a primary
First of all, sorry if this might be a stupid question. I'm very new
im in trouble with implemenetation of a service layer, i think i did not

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.