I have a table lets say
Table1 with columns Point_ID, Size, Age, Dist, Treatment
and Table 2 with columns Point_ID, Size, Age, Dist, Treatment, Path, Location.
Table 2 has similar data for Point_ID, Size, Age, Dist, Treatment as Table1 for some values.
I want to merge extra columns of Table 2 in Table1 such that there is no duplication and the resulted table looks likes "Point_ID, Size, Age, Dist, Treatment, Path, Location."
There is data in Table1 in columns Point_ID, Size, Age, Dist, Treatment which does not have path and location, so the path and location should be null for them.
What SQL query to be performed?.
Best Answer
Assuming
Point_ID
is a primary key or unique key shared by the two tables, then you can do this to create a new tableTable3
with the data you specified:For any row with
Point_ID
inTable1
that doesn't exist inTable2
thePath
andLocation
columns will be NULL. If it does exist, thePath
andLocation
columns will have the values fromTable2
. For any row withPoint_ID
inTable2
that doesn't exist inTable1
, the whole row will be added to the new tableTable3
.