Easiest way to extract owner-id from a third table

From: Rikard Bosnjakovic <rikard(dot)bosnjakovic(at)gmail(dot)com>
To: pgsql-novice(at)postgresql(dot)org
Subject: Easiest way to extract owner-id from a third table
Date: 2010-08-19 17:40:08
Message-ID: AANLkTimmNktgB1zyWpa+BQdqXXTQE-dURmEs=3UxPfw+@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

I have four tables:

users (id, name, ...);
components (id, owner_id (references users), ...);
images (id, filename);
component_images (id, components_id (references components), images_id
(references images));

This way, I can have unlimited amount of images per component.

Now I'm looking for a way to extract the owner-id (that's specified in
the components table) and the owner name while having only the
image_id at hand. I can ofcourse first select a row in
component_images and - in the application - extract the value for
components_id. Then I can use another query to find the owner id in
the components table, which will let me have the owner id.

Is there a way to achive all this without having to fiddle around in
the application? I haven't got the faintest idea of how to specify
this query.

--
- Rikard

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Thom Brown 2010-08-19 17:46:15 Re: Easiest way to extract owner-id from a third table
Previous Message Brad Nicholson 2010-08-19 14:16:25 Re: Performance monitoring?