Skip to content
Advertisement

Join a single column of value labels to multiple columns of values in another table in SQL

I have two tables: Preferences, which shows students’ meal preferences, and Key, which is a key to understanding what each of the values are for each meal item.

I am trying to figure out the most efficient way to assign value labels to each column of meal item values in Preferences from the single Item column from Key. In other words, I want to JOIN the two tables to create the following table:

Where each meal item value for each student in Preferences is matched to its appropriate label from the single Item column in Key.

Advertisement

Answer

I’m not sure about the most efficient way as you mentioned, but you can perform an inner join four times as the following:

See demo from db-fiddle.

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