Skip to content
Advertisement

How to replace duplicated columns with a foreign key?

Given that I have the following tables (datasets) made by python:

So the paitent table is:

and then the other table has the same columns patient_ID, Year and the month. These 3 columns are duplicated from patient table.

So, it is its final look of paitentPolyp

The question is:

How may i obtain a view from paitentPolyp which instead of patient_ID, Year and the month only has the ID of paitent?

So, my favorit output is:

Although, i am working with python, but a SQL solution is more welcome.

Advertisement

Answer

In Python:

In SQL:

Gives the following output:

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement