Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id 8C4E237C6BC for ; Mon, 12 Nov 2007 17:48:05 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 44236-04 for ; Mon, 12 Nov 2007 17:48:02 -0400 (AST) Received: from pyxis.powervt.com.ar (host3.powervt.com.ar [200.43.63.66]) by postgresql.org (Postfix) with ESMTP id DDE3437C686 for ; Mon, 12 Nov 2007 17:48:01 -0400 (AST) Received: from pcfhevia ([201.216.249.98]) by pyxis.powervt.com.ar (IPGroup Mail Server) with ESMTP id 1OT48953; Mon, 12 Nov 2007 18:47:57 -0300 From: "Fernando Hevia" To: "'Andreas'" , Subject: Re: design of tables for sparse data Date: Mon, 12 Nov 2007 18:48:19 -0300 Organization: IP-TEL Message-ID: <0c8501c82575$bd3cf830$8f01010a@iptel.com.ar> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Office Outlook 11 Thread-Index: Acgi1hYmMV60V+XcTzm/HggxPSdwDgCkRnvw X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3198 In-Reply-To: <4734632D.2010400@gmx.net> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200711/56 X-Sequence-Number: 29584 > --- Andreas Wrote: --- > ... > > MY QUESTIONS: Your questions have a strong "home-work" look. > > 1) How would I SELECT a report that looks like the first version of > the pupil table out of the 3 table design? > There must be a nontrivial SELECT statement that combines all 3 tables. > E.g. I want the result: > pupil_id, pupil_name, attends_to_english, ....., attends_to_football, > attends_to_swimming, attends_to_knitting > (42, Frank Miller, yes, ...., no, yes, yes) > (43, Suzy Smith, yes, ..., yes, yes, no) > ... You should check out the JOIN clause in select statements. Simple example: Select t1.col1, t2.col1, t2.col2 from t1 inner join t2 b on (t1.col1 = t2.col1) > > 2) Could I control the order in which those attends_to-columns appear > by a numerical field output_order? > You specify the order of output columns in the select statement. If you want to do this dynamically (say each user wants to configure its own order) you are really better of programming in your front-end application. No trivial solution in a pure SQL solution. It would probably require some dynamic sql and another table which holds de column printout order. > 3) Could I restrict the classes list so that only those appear when > there are pupils actually attending them in a given time frame? > 3) a) Like "competitve knitting" was only available from 2000-2005. > Now I'd produce a list of 2007 so there shouldn't appear an empty > knitting-column. --> classes.is_availlable > 3) b) Or it is availlable but no one has chosen it in 2007. --> > attends_to.in_year > Yes, you could. Read about different JOINS and WHERE clauses. ;) Regards, Fernando.