Given the following tables, how might I build a SQL query that includes a list of all the items from the "items" table, and a column for each color from the "colors" table that, for each item listed, indicates what colors the item has a relationship with.
If that is unclear at all, please let me know what additional information will help clarify. The table information and desired SQL result are below:
items table:
id | item_name
1 | 'item 1'
2 | 'item 2'
3 | 'item 3'
colors table:
id | color_name
1 | 'red'
2 | 'blue'
3 | 'green'
item_color table:
item_id | color_id
1 | 1
1 | 3
2 | 2
2 | 3
3 | 2
Desired SQL query result:
item_name | red | blue | green
'item 1' | 1 | null | 1
'item 2' | null| 1 | 1
'item 3' | null| 1 | null
Thanks, Colin