Received: from mercury.Sun.COM (mercury.Sun.COM [192.9.25.1]) by hub.org (8.9.2/8.9.1) with SMTP id RAA39884 for ; Thu, 4 Feb 1999 17:15:47 -0500 (EST) (envelope-from dimitri@france.Sun.COM) Received: from France.Sun.COM ([129.157.188.1]) by mercury.Sun.COM (SMI-8.6/mail.byaddr) with SMTP id OAA16339; Thu, 4 Feb 1999 14:15:08 -0800 Received: from sybille.France.Sun.COM by France.Sun.COM (SMI-8.6/SMI-SVR4-sd.fkk200) id XAA28792 for ; Thu, 4 Feb 1999 23:15:06 +0100 Received: from dimitri (pc_dimitri [129.157.186.244]) by sybille.France.Sun.COM (8.8.8+Sun/8.8.8) with SMTP id XAA28882; Thu, 4 Feb 1999 23:15:06 +0100 (MET) Sender: dim@sybille.France.Sun.COM Message-ID: <36BA1BBB.323A76EB@france.sun.com> Date: Thu, 04 Feb 1999 22:14:19 +0000 From: Dimitri Organization: Sun Microsystems X-Mailer: Mozilla 3.04Gold (X11; I; Linux 2.0.36 i586) MIME-Version: 1.0 To: "Jackson, DeJuan" CC: pat@patoche.org, pgsql-sql@postgreSQL.org Subject: Re: [SQL] problem with join & count References: Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Jackson, DeJuan wrote: > > try: > SELECT t1.name, count(t2.tag) > FROM t1, t2 > WHERE t1.number = t2.number > GROUP BY t1.number, t1.name ______________^ your query will never work :)), you have to miss t1.number... Best regards! (dim) > > -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/ > > > > -- ===================================================== Dimitri KRAVTCHUK (dim) Sun Microsystems Benchmark Engineer France dimitri@France.Sun.COM =====================================================