awsmsce
awsmsce

Reputation: 194

Query Efficiency - relational data lookups for comments, likes, etc

Relational Database with these tables:

To pull comments for a product is just a join, but to also include the user's image_url I must do a lookup for each comment to find it's associated user data.

I can think of a few ways to handle this:

I'm just assuming that there is a better way of dealing with this problem to make it super clean. Can anyone suggest a better alternative?

Thanks in advance!

Upvotes: 0

Views: 39

Answers (1)

jaadooviewer
jaadooviewer

Reputation: 368

I am just curious: why can't it be a three way join? You are joining Products with Comments on product_id. Why not join it with Users as well on user_id (which is in Comments)? Since it is too simple and obvious, I must be missing something but still I wanted to throw it out there :-)

Upvotes: 1

Related Questions