Joining three tables in SQL with duplicated column names
Joining three tables in SQL with duplicated column names
I have three tables in SQL which I need to join them together and this is a simplified version:
Table 1 Columns
Person ID (pID)
Fav Soccer Team (favST)
Fav Soccer Player (favSP)
Table 2 Columns
Person ID (pID)
Fav Soccer Team (favST)
Fav Soccer Player (favSP)
Table 3 Columns
Person ID (person_ID)
Person Name (pName)
The problem is that each person may appear in both Table 1 and Table 2. You can take for example that Table 1 reflects the favourite team and player in 2017, and Table 2 reflects the favourite team and player in 2018.
I have to create a query which will join them all and show
Result Columns
Person ID (pID)
Person Name (pName)
Favourite Soccer Team (favST)
Favourite Soccer Player (favSP)
Table1/Table2 <--- which table this row of data is from
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
I removed the incompatible database tags. Please tag only with the database you are really using.
– Gordon Linoff
1 min ago