Is it possible to write a SQL query to return specific rows, but then join some columns of those row
Posted
by Rob
on Stack Overflow
See other posts from Stack Overflow
or by Rob
Published on 2010-04-13T15:39:02Z
Indexed on
2010/04/13
15:42 UTC
Read the original article
Hit count: 191
I'm having trouble wrapping my head around how to write this query.
A hypothetical problem that is that same as the one I'm trying to solve:
Say I have a table of apples
. Each apple
has numerous attributes, such as color_id
, variety_id
and the orchard_id
they were picked from.
The color_id
, variety_id
, and orchard_id
all refer to their respective tables: colors
, varieties
, and orchards
.
Now, say I need to query for all apples
that have color_id = '3'
, which refers to yellow
in the colors
table.
I want to somehow obtain this yellow
value from the query.
Make sense?
Here's what I was trying:
SELECT * FROM apples, colors.id WHERE color_id = '3'
LEFT JOIN colors ON apples.color_id = colors.id
© Stack Overflow or respective owner