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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:50:55+00:00 2026-05-25T10:50:55+00:00

I have a tables (simplified) like this: Lender Id (PK) AgencyCode1 AgencyCode2 AgencyCode3… AgencyCode20

  • 0

I have a tables (simplified) like this:

Lender
   Id (PK)
   AgencyCode1
   AgencyCode2
   AgencyCode3...
   AgencyCode20

Agency
   AgencyCode
   AgencyName

The Lender table is denormalized data coming from a view for reporting. I need one row in my output for each Lender and I need to join the agency codes to an agency table to get the display name for each agency.

The resulting output I am looking for in each row is:

LenderId, AgencyCode1, AgencyName1, ... AgencyCode20, AgencyName20

What is the pattern that strikes the best balance between performance and (developer) productivity to query something like this?

–Edit, Agency Code wasn’t a primary key, as I had originally indicated.

  • 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-25T10:50:56+00:00Added an answer on May 25, 2026 at 10:50 am

    Echoing @Martin Smith’s comment, unpivot, join, and pivot would probably be the most efficient, performance wise — and, through working out the intricacies of how to unpivot and pivot, your developers would be more expereienced and thus more productive over time.

    Alternatively, if there are 20 and always 20 denormalized columns, you could just write out 20 left outer joins (under the assumption that ever Lender is not related with 20 Agencies). This is ugly code, and would require SQL to process 20 joins… but if the Agency table is small (where I’d call 8 pages/1 extent small), then the overall processing time might be relatively short. Testing would be called for, to determine which performs best.

    As regards to developer productivity overall, keep track of how long everything takes (including posting to SO). When it’s done, tally everything up, and use it to show how much time was wasted by your developers having to work with poorly designed tables.

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

Sidebar

Related Questions

I have 2 tables which in simplified form look like this: Products( id: int,
I have a table like this (simplified): ID | Name | Parent --------------------------------- 1
Basically the situation is like this (simplified, pseudo code): I have 2 TABLES person
I have 2 related database tables which in simplified form look like this Product(
I have a MySQL database with two tables (simplified for this question): movies table
I have the following two tables (simplified for this question): CREATE TABLE team (
I have two tables built like this (this is just a simplified and non-proprietary
I have a table that simplified looks like this: create table Test ( ValidFrom
We have a simplified table like this: TYPE; VALUE AA; 10 BB; 7 CC;
So I have a database that is setup sort of like this (simplified, and

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.