Thanks in advance for your help:
[People]
table has two columns:
[Marriages]
table has three columns:
I want to SELECT the following columns:
I think I need to use a SELECT
statement with a JOIN
, but I'm not sure how to assign a unique alias to each PersonName
. This is what I have so far (that doesn't work):
SELECT
[Marriages].[MarriageID],
[People].[PersonName] AS aName,
[People].[PersonName] AS bName
FROM
[Marriages]
JOIN
[People] ON [Marriages].[PersonIDa] = [People].[PersonID]
JOIN
[People] ON [Marriages].[PersonIDb] = [People].[PersonID]
Thanks again...
Does this match what you're trying to accomplish?
SELECT m.[MarriageID], peopleA.[PersonName] AS aName, peopleB.[PersonName] AS bName
FROM [Marriages] M
JOIN [People] peopleA ON m.[PersonIDa] = peopleA.[PersonID]
JOIN [People] peopleB ON m.[PersonIDb] = peopleB.[PersonID]
I think you're trying to do this...
SELECT
m.[MarriageID],
pa.[PersonName] AS aName,
pb.[PersonName] AS bName
FROM [Marriages] m
JOIN [People] pa ON m.[PersonIDa] = pa.[PersonID]
JOIN [People] pb ON m.[PersonIDb] = pb.[PersonID];
You will need something like:
Select MarriageID, a.PersonName, b.PersonName
From Marriages m
Join People a On a.PersonID = m.Person1ID
Join People b on b.PersonID = m.Person2ID
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With