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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T15:30:18+00:00 2026-06-16T15:30:18+00:00

I have joined the same 2 tables twice using different aliases in a SQL

  • 0

I have joined the same 2 tables twice using different aliases in a SQL query to enable me to select 2 (potentially but not always) different address ids which then link in to the address table.

SELECT C.court_id, C.court_name, CA.court_address, CA2.court_address...
FROM court C " +
JOIN court_addr CA ON C.court_addr_id = CA.court_addr_id " +
JOIN court_addr CA2 ON C.court_postal_addr_id = CA2.court_addr_id " + ...

Now when trying to output the results of this query using ASP.NET C# I’m unsure how to specify which of the two addresses to Response.Write. Putting the alias in front of the column name (as in the 4th string value below) doesn’t work and brings up an error. Is there a way of differentiating between the two addresses in C# despite them both having the same column name in the database?

while (myDataReader.Read())
{
    string court_id = myDataReader["court_id"].ToString();
    string court_name = myDataReader["court_name"].ToString();
    string court_address = myDataReader["court_address"].ToString();
    string court_postal_address = myDataReader["CA2.court_address"].ToString(); 
    etc.....

Thanking you muchly in advance

  • 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-16T15:30:19+00:00Added an answer on June 16, 2026 at 3:30 pm

    You should use an alias in your sql to distinguish them, then you will be able to return the correct value:

    SELECT C.court_id, 
      C.court_name, 
      CA.court_address as CACourtAddress, 
      CA2.court_address as CA2CourtAddress
    FROM court C " +
    JOIN court_addr CA ON C.court_addr_id = CA.court_addr_id " +
    JOIN court_addr CA2 ON C.court_postal_addr_id = CA2.court_addr_id " + ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a query with about 6-7 joined tables and a FREETEXT() predicate on
I currently have two joined tables in a SQL Server database, one with news
I have one Linq to SQL query that simply joins three tables and then
here is the query, I have inner joined 3 tables, Now i am looking
What causes a query of joined tables to display duplicate data. I have tried
I have a SQL query where I want to join two tables to gether
I have the following SQL query that performs a subquery and joins two tables
I have an SQL query that joins few tables and I want to filter
I am building a photo uploading website and I have joined two tables together
I used the mapping solution from this question to have a joined component. But

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.