I’m reading from a table that is not normalized (not my choice) and trying to map fields within it to another table. Is there a way to do this in one trip? I’m using Microsoft SQL.
TableA:
ID
FieldX1_ID (fixed set of fields that could have been better normalized)
FieldX2_ID
FieldX3_ID
TableB:
FieldX_ID (matches ID's in TableA's fields)
FieldX_Value
I would like the output rows to be:
TableA.ID, TableB.FieldX_Value for TableA.FieldX1_ID, TableB.FieldX_Value for TableA.FieldX2_ID, etc…
You can get the results in two ways. I’m not sure from your description which one you’re after.
To have the results appear in a normalized fashion (you get three rows):
To have the results appear in de-normalized fashion (you get one row):