Skip to content
Advertisement

SQL join and Bring in 1 column into 2 columns

enter image description here

enter image description here

I have two tables shown as above. I want to create a select statement that would have the following result:

enter image description here

Basically, I want to join on ‘Model’ and ‘Num’ columns and bring ‘Val’ vales but break it into two columns based on ‘Ver’.

Advertisement

Answer

You can join and do conditional aggregation:

Alternatively, you can join twice – depending on your dataset, this might (or might not) perform better:

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