Skip site navigation (1) Skip section navigation (2)

Re: Selecting from two tables

From: mauro(dot)folcarelli(at)sistinf(dot)it
To: pgsql-php(at)postgresql(dot)org
Subject: Re: Selecting from two tables
Date: 2004-01-15 07:44:09
Message-ID: OF5DA66277.51C42621-ONC1256E1C.002A6AD2@sistinf.it (view raw or flat)
Thread:
Lists: pgsql-php
>> 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


pgsql-php by date

Next:From: Nick BarrDate: 2004-01-15 08:37:40
Subject: Re: Selecting from two tables
Previous:From: Michael HannaDate: 2004-01-14 23:33:13
Subject: Selecting from two tables

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group