Skip to content
Advertisement

How to merge SQL results?

There is lot of questions on merging SQL results. Here is my case that has two different SQL results.

userID   Car
1        Ford
2        Honda
3        Toyota
userID   Color
1        Red
2        Silver
3        White

Is there a way to merge both of the above into the follows in SQL:

userID   Car      Color
1        Ford     Red
2        Honda    Silver
3        Toyota   White

Advertisement

Answer

This looks like a join:

select ca.user_id, ca.car, co.color
from cars ca join
     colors co
     on ca.user_id = co.user_id;
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement