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
Solved

Doable? Left join to 2 tables but have same alias

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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
kill process lock Sql server 9 64
SQL Server Insert where not exists 24 46
Query Syntax 17 43
Parse this column 6 27
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.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

829 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