Reputation: 4008
I have 3 tables:
Item and OwnerImage
have Foreign Key to Owner
. Not all Owner
have Item
(s)
Item
id name owner_id (fk)
1 alpha 1
2 beta 1
Owner
id name
1 owner1
2 owner2
OwnerImage
id name owner_id (fk)
1 image1 1
2 image2 1
I want to get a list of all Items, and their Owner and OwnerImage, which I can do with a join.
But it is possible, to get the Owner as a 'property' of Item from database:
Item.Owner.OwnerImage (like an object)
At this moment I'm doing 3 queries and do the matching using loops
in code(python), but I want to know if it is possible with one query;
Upvotes: 0
Views: 20
Reputation: 11205
You can use a join
to select data for a given value in another table where a relationship exists:
select owner
from owner o1
inner join ownerimage o2
on o2.owner_id = o1.id
Not sure how EVENT
ties into this, but this should get you started
Upvotes: 1