I currently have a join that can results in multiple rows. Instead of using a join to get return results I would like to only return one but a particular column from the join table to be listed out in columns to show each one with only the one row.
select u.city, u.state, u.county, u.zip, c.local_code
from usa u
left join code c where c.zip = u.zip
where zip = '90210'
Sample result
city state county zip local_code
----------------------------------------------------
salt lake utah lake county 90210 12A
salt pond utah lake county 90210 12C
sea salt utah lake county 90210 12B
Since there are multiple cities for that one zip, I would like to split that up into separate columns instead and name them local_code_1 - local_code_6 to fill any potential codes that come through in one row and remove the city name.
So I would like results like:
state county zip local_code_1 local_code_2 local_code_3 local_code_4 local_code_5 local_code_6
utah lake county 90210 12A 12C 12B