[eluser]introvert[/eluser]
I have one more question regarding relations..
I have 4 tables:
blogs
campaigns
feeds
items
The relations are:
blog belongs to campaign (one-to-one)
each feed belongs to 1 campaign
each item belongs to 1 feed
Now if I have item id and I want to get the blog record that belongs to the same campaign as the feed of that item, I should retrive the parent's feed_id from item.feed_id and then campaign_id from feed.campaign_id and then find the proper blog.campaign_id
This sounds pretty complicated design and I have some concerns if it would be better to just store the campaign_id with each item so that I can then just join blogs and items tables by campaign_id?
How would you design that?
I dont want to duplicate data and make it hard to control so I should probably go for something like:
Code:
SELECT blogs.*
FROM blogs
INNER JOIN campaigns ON blogs.campaign_id = campaigns.id
INNER JOIN feeds ON feeds.campaign_id = campaigns.id
INNER JOIN items ON items.feed_id = feeds.id
WHERE items.id = ?