X-Original-To: pgsql-php-postgresql.org@localhost.postgresql.org Received: from localhost (neptune.hub.org [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id EB628D1B48D for ; Thu, 15 Jan 2004 07:49:06 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 95144-03 for ; Thu, 15 Jan 2004 03:48:37 -0400 (AST) Received: from www.sistinf.it (unknown [212.17.216.45]) by svr1.postgresql.org (Postfix) with ESMTP id 73C3CD1B476 for ; Thu, 15 Jan 2004 03:48:35 -0400 (AST) Received: from lngsirm01.sistinf.it ([10.10.0.163]) by www.sistinf.it (Lotus Domino Release 5.0.8) with ESMTP id 2004011508434180:67966 ; Thu, 15 Jan 2004 08:43:41 +0100 Received: from lngsito01.sistinf.it ([10.11.0.5]) by lngsirm01.sistinf.it (Lotus Domino Release 5.0.8) with ESMTP id 2004011508520971:7605 ; Thu, 15 Jan 2004 08:52:09 +0100 Subject: Re: Selecting from two tables To: pgsql-php@postgresql.org X-Mailer: Lotus Notes Release 5.0.8 June 18, 2001 Message-ID: From: mauro.folcarelli@sistinf.it Date: Thu, 15 Jan 2004 08:44:09 +0100 MIME-Version: 1.0 X-MIMETrack: Serialize by Router on lngsito01/GSI/it(Release 5.0.6a |January 17, 2001) at 15/01/2004 08.44.10, Itemize by SMTP Server on lngsirm01/GSI/it(Release 5.0.8 |June 18, 2001) at 15/01/2004 08.52.09, Serialize by Router on lngsirm01/GSI/it(Release 5.0.8 |June 18, 2001) at 15/01/2004 08.52.11, Serialize complete at 15/01/2004 08.52.11, Itemize by SMTP Server on lngsirm02/GSI/it(Release 5.0.8 |June 18, 2001) at 15/01/2004 08.43.41, Serialize by Router on lngsirm02/GSI/it(Release 5.0.8 |June 18, 2001) at 15/01/2004 08.43.49, Serialize complete at 15/01/2004 08.43.49 Content-type: text/plain; charset=us-ascii X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200401/16 X-Sequence-Number: 2532 >> I have a table called Jobs and another called Applications. >> I can query all Job rows, but how do I also include the number >> of Application rows for each Job row in the SELECT statement? Try this way: (1) CREATE VIEW viewappl AS SELECT jobid ,count(*) as numappl FROM application GROUP BY jobid; (2) SELECT job.jobid ,job.login ,job.jobtitle ,job.jobdescrip ,job.jobkeywords ,job.valid ,job.postdate ,viewappl.numappl FROM job , viewappl where job.jobid = viewappl.jobid order by job.jobid ; I hope it's ok. Hi, Mauro