pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Oliver Elphick <olly@lfix.co.uk>
To: Andy Lewis <alewis@themecca.net>
Cc: pgsql-sql@postgreSQL.org
Subject: Re: [SQL] 2 Table Select
Date: Thu, 27 May 1999 20:34:54 +0100
Message-ID: <199905271934.UAA07954@linda.lfix.co.uk> (raw)
In-Reply-To: <alewis@themecca.net> <Pine.LNX.4.05.9905271105190.22984-100000@tmg.themecca.net>

Andy Lewis wrote:
  >I am trying to get the _total_ number of jobs
  >that each company has in the db.
  >
  >In other words I want to get each distinct company
  >that has jobs in the jobs table and the _total_ number 
  >of jobs that it has in the jobs table.
  >
  >What would be the best query that I could use?
  >
  >I'm using 6.4.2.
  >
  >Table = jobs
  >+-------------+---------------+-------+
  >| Field       | Type          | Length|
  >+-------------+---------------+-------+
  >| job_id      | int4 not null |     4 |
  >| company_id  | int4          |     4 |
  >| title       | varchar()     |    50 |
  >...
  >+-------------+---------------+-------+
  >
  >Table = company
  >+--------------+---------------+-------+
  >|Field         |Type           | Length|
  >+--------------+---------------+-------+
  >| company_id   | int4 not null |     4 |
  >| company_name | varchar()     |   100 |
  >| email        | varchar()     |   100 |
  >...
  >+--------------+---------------+-------+
 
select c.company_id, count(j.job_id)
   from company as c, jobs as j
   where c.company_id = j.company_id
   group by c.company_id;

-- 
Oliver Elphick                                Oliver.Elphick@lfix.co.uk
Isle of Wight                              http://www.lfix.co.uk/oliver
               PGP key from public servers; key ID 32B8FAA1
                 ========================================
     "All that the Father giveth me shall come to me; and
      him that cometh to me I will in no wise cast out."
                                      John 6:37 





view thread (4+ messages)  latest in thread

Message-ID: <199905271934.UAA07954@linda.lfix.co.uk>
Permalink:  ../199905271934.UAA07954@linda.lfix.co.uk/
Also on:    postgresql.org/message-id/199905271934.UAA07954@linda.lfix.co.uk

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: olly@lfix.co.uk, alewis@themecca.net
  Subject: Re: [SQL] 2 Table Select
  In-Reply-To: <199905271934.UAA07954@linda.lfix.co.uk>
  References: <199905271934.UAA07954@linda.lfix.co.uk>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox