Hi all!
I came across this problem earlier, and have been banging my head against the wall for what ‘seems’ like should be a relatively simple issue. Actually kinda amazed I haven’t come across this before.
I have two tables ‘colors’ and ‘products’.
The products table has a field for product_color, which relates to the colors table.
Here is a sample query
SELECT
products.*
, colors.hex
INNER JOIN colors
ON colors.id = products.product_color_id
WHERE products.product_id = '123'
Well, all was well and happy until I was asked to add another color field in the products table.
So… each product will now have two fields that relate to the colors table and I need to join the hex value for both of them… I’ve tried multiple things and nothing seems to give me what I need. I’m open to ideas suggestions anything. Thanks in advance for any guidance.
Hopefully this will illustrate what i’m ‘trying’ to do.
SELECT
products.*
, colors.hex as product_color
, colors.hex as bag_color_hex
INNER JOIN colors
ON colors.id = products.product_color_id
INNER JOIN colors
ON colors.id = products.bag_color_id
WHERE products.product_id = '123'