Solved

Doable? Left join to 2 tables but have same alias

Posted on 2013-02-03
2
278 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
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Naughty Me. While I was changing the database name from DB1 to DB_PROD1 (yep it's not real database name ^v^), I changed the database name and notified my application fellows that I did it. They turn on the application, and everything is working. A …
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.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

708 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now