MySQL, join one item to multiple items in a single query

Posted by bschaeffer on Stack Overflow See other posts from Stack Overflow or by bschaeffer
Published on 2010-05-19T01:50:49Z Indexed on 2010/05/19 2:00 UTC
Read the original article Hit count: 217

Filed under:
|

Say I've got two tables. One contains a list of items, and one contains pictures of the items.

Something like this:

Items

+----+---------+
| id | name    |
+----+---------+
|  1 | oranges | 
|  2 | apples  | 
+----+---------+

Pictures

+----+---------+
| id | item_id |
+----+---------+
| 1  | 1       | 
| 2  | 2       | 
| 3  | 2       | 
+----+---------+

My question is this: is it possible in a single query to select item 2 from Items and join all the rows in the Pictures table whose item_id references that same id?

I am sure I've tried almost everything I can think of, but nothing is coming to mind. I apologize if the answer to this is simple, but It's just escaping me right now.

© Stack Overflow or respective owner

Related posts about mysql

Related posts about join