Received: from bjke.com (firewall-user@ganymede.bjke.com [144.210.8.38]) by hub.org (8.9.2/8.9.1) with ESMTP id QAA37047 for ; Thu, 4 Feb 1999 16:59:11 -0500 (EST) (envelope-from djackson@cpsgroup.com) Received: by bjke.com; id OAA05718; Thu, 4 Feb 1999 14:59:26 -0600 (CST) Received: from cpsmail.cpsgroup.com(144.210.12.11) by gauntlet.bjke.com via smap (4.1) id xmaa04769; Thu, 4 Feb 99 14:58:40 -0600 Received: by cpsmail with Internet Mail Service (5.0.1458.49) id ; Thu, 4 Feb 1999 15:00:50 -0600 Message-ID: From: "Jackson, DeJuan" To: pat@patoche.org, pgsql-sql@postgreSQL.org Subject: RE: [SQL] problem with join & count Date: Thu, 4 Feb 1999 15:00:47 -0600 X-Priority: 3 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.0.1458.49) Content-Type: text/plain try: SELECT t1.name, count(t2.tag) FROM t1, t2 WHERE t1.number = t2.number GROUP BY t1.number, t1.name -DEJ > -----Original Message----- > From: pat@patoche.org [mailto:pat@patoche.org] > Sent: Thursday, February 04, 1999 2:39 PM > To: pgsql-sql@postgreSQL.org > Subject: [SQL] problem with join & count > > > 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/ > >