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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T13:22:54+00:00 2026-06-10T13:22:54+00:00

I have to build an application on an existing SQL database and I came

  • 0

I have to build an application on an existing SQL database and I came upon this situation.

There’s a table (call it T1) where several fields reference values from another table (T2), which basically is made up of just 2 fields, Id and Name. As a consequence, T2 holds data of different nature and meaning, because the fields in T1 that relate to it are of very different kinds. (This seems to me an unusual design.)

My question: given this design, how I can build a join query in order to get the value of T2.Name related to each T1 field.

EDIT

I could get what I want by doing one query per field:

SELECT t2.name AS name1
FROM t1
INNER JOIN t2
ON t1.field1 = t2.id;

SELECT t2.name AS name2
FROM t1
INNER JOIN t2
ON t1.field2 = t2.id;

SELECT t2.name AS name3
FROM t1
INNER JOIN t2
ON t1.field3 = t2.id;

But this is nonsense. So how could I pack all this in one single query?

  • 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-10T13:22:55+00:00Added an answer on June 10, 2026 at 1:22 pm

    You need to alias references to t2 to get corresponding names:

    SELECT alias1.name AS name1,
           alias2.name AS name2,
           alias3.name AS name3
      FROM t1
     INNER JOIN t2 alias1
        ON t1.field1 = alias1.id
     INNER JOIN t2 alias2
        ON t1.field2 = alias2.id
     INNER JOIN t2 alias3
        ON t1.field3 = alias3.id;
    

    You might want to replace inner with left joins if foreign keys are nullable.

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

Sidebar

Related Questions

We have several applications that are updating a certain ms sql 2005 table (asp.net
We have several applications that are updating a certain ms sql 2005 table (asp.net
I have a SQL Express database, and I'd like a very simple forms application
I have a web application solution existing under Visual Studio 2010. Part of this
Is there a way to build a C# wrapper for an existing application that
I have a database that I'll have to use to build my application. It
I have an application build in C# for reading and saving SMS and MMS,
I have build my very first application to Android and I want now to
I have used JMS in the past to build application and it works great.
I have a flex application build with actionscript 3 on flex builder with unit

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.