X-Original-To: pgsql-sql@postgresql.org Received: from localhost (developer.postgresql.org [64.117.224.193]) by developer.postgresql.org (Postfix) with ESMTP id D4FA79259C1 for ; Mon, 26 May 2003 09:55:24 -0400 (EDT) Received: from developer.postgresql.org ([64.117.224.193]) by localhost (developer.postgresql.org [64.117.224.193:10024]) (amavisd-new) with ESMTP id 89850-05 for ; Mon, 26 May 2003 09:55:23 -0400 (EDT) Received: from smtp.blueyonder.co.uk (pc-80-195-188-198-gl.blueyonder.co.uk [80.195.188.198]) by developer.postgresql.org (Postfix) with ESMTP id 18D299259BE for ; Mon, 26 May 2003 09:55:23 -0400 (EDT) Received: from reddragon.localdomain ([127.0.0.1] helo=localhost) by smtp.blueyonder.co.uk with esmtp (Exim 4.10) id 19KIRs-0001oh-00 for pgsql-sql@postgresql.org; Mon, 26 May 2003 14:55:37 +0100 Date: Mon, 26 May 2003 14:55:36 +0100 (BST) From: Peter Childs X-X-Sender: peter@RedDragon.Childs Cc: pgsql-sql@postgresql.org Subject: Re: Many-to-Many relation In-Reply-To: <3ED20C8D.6EE46DFF@darya.nio.org> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: by amavisd-new X-Archive-Number: 200305/497 X-Sequence-Number: 13662 On Mon, 26 May 2003, Mukta Telang wrote: > Hi, > > I am designing a database of paper publications. > > A paper has one or more authors and an author has one or more papers. > In this way there is many-to-many relation. > > An author of a paper has a "level", that is an author of a paper of > level one is the main author of the paper and the author > with level two is the second author of the paper and so on. > > So we have following tables: > 1. author > 2. paper > 3. author_paper > > The attributes of author are: > 1. author_id > 2. name > > The attributes of paper are: > 1. paper_id > 2. journal > 3. year > 4. volume > 5. issue > > The attributes of author_paper are: > 1. author_id > 2. paper_id > 3. level SELECT * FROM author_paper full join (author on (author_paper.author_id = author.author_id) full join paper on (author_paper.paper_id = paper.paper_id)) ORDER BY paper.paper_id, author_paper.level; I think is what you want, You will need to replace the * with the fields you want of course! (Bung "CREATE VIEW AS" to create the view) If you don't want to list authors without papers or papers with no authors you will need to change "full join" to "left join" and you may need to swap the order the joins occur in if you want one but not the other. Peter Childs > > Now I want to create a view which displays all the information about > every paper.That is title,year,journal,volume, issue and all the authors > of the paper sorted according to their level. > > How to do this? > > Thanks in advance, > > Mukta > > ---------------------------(end of broadcast)--------------------------- > TIP 3: if posting/reading through Usenet, please send an appropriate > subscribe-nomail command to majordomo@postgresql.org so that your > message can get through to the mailing list cleanly >