What are good ways to store Authors, Articles, Magazines relationship in Relational Database?
-
I have following entities: Author: Id, Name Article: Id, Title, Contents, Magazine_Id AuthorArticle: Author_Id, Article_Id Magazine: Id, Title Author - Article is Many to Many. What is the most efficient way to get the list of all the Magazines in which the Author's articles were published knowing the Author.Id. Are there better design options than this?? Currently I first select all the Articles and the Select DISTINCT Magazine_ID from them.
-
Answer:
The table structures you have mentioned should work pretty well. For purposes of clarity and consistency, let's rename the columns. AUTHOR (author_id, author_name) MAGAZINE (magazine_id, magazine_name) ARTICLE (article_id, article_title, contents, magazine_id) AUTHOR_ARTICLE (author_id, article_id) As for the query, since you want to fetch data for a single author at a given time, keep the query on Author table separate (as a sub-query): SELECT DISTINCT mag.magazine_title FROM Magazine mag, Article art, Author_Article aa WHERE mag.magazine_id = art.magazine_id AND art.article_id = aa.article_id AND aa.author_id = (SELECT auth.author_id FROM Author auth WHERE auth.author_id = '<enter id here>')
Karthik Selvaraj at Quora Visit the source
Related Q & A:
- What would be some good ways to advertise locally?Best solution by Yahoo! Answers
- What are good ways to save up for an iPod Touch?Best solution by wikihow.com
- What are good ways to promote my website?Best solution by Yahoo! Answers
- What are good ways to get the "Last Second Bid" on eBay successfully?Best solution by ebay.com
- What are good ways for personal fund raising?Best solution by wiki.answers.com
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.