Given the following example:
fav_colors
-----------------------
id col1 col2 col3
-----------------------
01 01 03 03
02 04 02 01
03 01 03 02
colors
-----------
id colors
-----------
01 green
02 red
03 blue
04 orange
What kind of SELECT statement works to pull the string values from colors for all 3 colors of a particular ID in the fav_colors table?
Something like:
SELECT col1, col2, col3
FROM fav_colors
INNER JOIN ?
WHERE fc.id = 03;
I’m guessing a fav_color array would make this easier, but am relying on these values being separate columns. How do you join the same table to multiple columns in another table?
Edit: All the answers below technically work. Agree that if relying heavily on multiple color info, you’re better off recording each color as a referenced row in fav_colors. Thanks!
Table aliases…
Ideally, you’d have a
fav_colorstable more like:You might have to tweak some of that syntax for your particular DBMS.