pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: pat@patoche.org
To: pgsql-sql@postgresql.org
Subject: problem with join & count
Date: Thu, 04 Feb 1999 21:39:28 +0100 (CET)
Message-ID: <199902042039.VAA00553@vagabond.bde.espci.fr> (raw)

Hi,

I don't succeed to build an SQL to do the task i describe below.
If someone can helps, thanks in advance.

I have two tables

number  | name
--------------
 1      | toto
 2      | titi
 3      | tutu

(here the number is a primary key)

and

number  |  tag
---------------
 1      | alpha
 1      | beta
 2      | gamma
 3      | zeta
 3      | epsilon
 
the number in the left column is the same of the number in the first table,
but can appear in that second table many times.

i need an sql query that will return:

name   |  how_often
-------------------
 toto  | 2
 titi  | 1
 tutu  | 2

that is, the result table should contain all names present in the first table
and then the number of times the number associated with the name appears in
the second table. 

Thanks a lot for your help.

Patrick

/\//\/\/\\/\/\//\/\\/\/\\/\\/\//\/\\/\//\/\\/\//\/\\/\//\/\\
Patrick M.   pat@patoche.org    http://www.patoche.org/




view thread (7+ messages)  latest in thread

Message-ID: <199902042039.VAA00553@vagabond.bde.espci.fr>
Permalink:  ../199902042039.VAA00553@vagabond.bde.espci.fr/
Also on:    postgresql.org/message-id/199902042039.VAA00553@vagabond.bde.espci.fr

 · 

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: pat@patoche.org
  Subject: Re: problem with join & count
  In-Reply-To: <199902042039.VAA00553@vagabond.bde.espci.fr>
  References: <199902042039.VAA00553@vagabond.bde.espci.fr>

* 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