Solved

Doable? Left join to 2 tables but have same alias

Posted on 2013-02-03
2
284 Views
Last Modified: 2013-02-03
I have a table that has some data in it. I created a new table but I cant get rid of the old one. For old/orig data, I still want to go to table1 and get the info. Anyway I can have the same alias for both the old and new table so I could pull data from both tables? This is what I have:

SELECT
nmp.id AS nonMemberProviderId,
ipn.id AS nonMemberPatientId,
ISNULL(CAST(dfl.id AS VARCHAR(MAX)),'') AS fileRowId
...

from
 .....
  LEFT JOIN dbo.Doc_Files_Letter dfl ON dfl.patientId = ipn.id
  LEFT JOIN dbo.LetterFiles dfl ON dfl.patientId = ipn.id
0
Comment
Question by:Camillia
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 6

Accepted Solution

by:
liija earned 500 total points
ID: 38849111
No, same alias cannot be used twice.
But with the same script you could unite the data from two tables - depending on your data like this:

SELECT
nmp.id AS nonMemberProviderId,
ipn.id AS nonMemberPatientId,
ISNULL(CAST(dfl.id AS VARCHAR(MAX)), CAST(dfl_new.id AS VARCHAR(MAX)) AS fileRowId
...

from
 .....
  LEFT JOIN dbo.Doc_Files_Letter dfl ON dfl.patientId = ipn.id
  LEFT JOIN dbo.LetterFiles dfl_new ON dfl_new.patientId = ipn.id
0
 
LVL 7

Author Comment

by:Camillia
ID: 38849186
let me try
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question