I’m no SQL expert so excuse if my question sounds silly.
I have a Multi-Lookup table:
ID ProID AmID
The ID is an identity column and auto-generates the ID on insert. The ProID and the AmID links to a Candidate table, on the ID column in that.
I need to create a View that will return the Firstname Lastname AS Pro and Firstname Lastname AS Am in a single view, along with the ID from the Candidate table.
ID Pro ProID Am AmID
1 Name Surname 1 Name Surname 2
2 Name Surname 3 Name Surname 78
etc
I created two separate select statements for both the pro and the am candidate, but don’t know how to merge them into a single statement?
SELECT T2.[ID],
T2.[Firstname] + ' ' + T2.[Lastname] AS 'Pro'
FROM [Teams] AS T1
INNER JOIN [Candidate] AS T2
ON T1.ProID = T2.ID
SELECT T2.[ID],
T2.[Firstname] + ' ' + T2.[Lastname] AS 'Am'
FROM [Teams] AS T1
INNER JOIN [Candidate] AS T2
ON T1.AmID = T2.ID
I looked this up, and it seems that I would need to do a RIGHT JOIN on this, but it screws up the results.
Is this scenario possible, or will I have to settle for two distinct calls to the SQL?
you need to basically join the table
Candidateon yourTeamstable twice so you can get the equivalent value for each column.If one of the columns is nullable,
LEFT JOINis needed thanINNER JOINso non-matching values will still be on the list of result.To fully gain knowledge about joins, kindly visit the link below:
To create
VIEW