Re: [SQL] problem with join & count

From: Dimitri <dimitri(at)france(dot)Sun(dot)COM>
To: "Jackson, DeJuan" <djackson(at)cpsgroup(dot)com>
Cc: pat(at)patoche(dot)org, pgsql-sql(at)postgreSQL(dot)org
Subject: Re: [SQL] problem with join & count
Date: 1999-02-04 22:14:19
Message-ID: 36BA1BBB.323A76EB@france.sun.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-interfaces pgsql-sql

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(at)patoche(dot)org [mailto:pat(at)patoche(dot)org]
> > Sent: Thursday, February 04, 1999 2:39 PM
> > To: pgsql-sql(at)postgreSQL(dot)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(at)patoche(dot)org http://www.patoche.org/
> >
> >

--
=====================================================
Dimitri KRAVTCHUK (dim) Sun Microsystems
Benchmark Engineer France
dimitri(at)France(dot)Sun(dot)COM
=====================================================

In response to

Browse pgsql-interfaces by date

  From Date Subject
Next Message bcurnow 1999-02-04 22:39:31 JBuilder2 and colons/typecasting
Previous Message Karsten Kaus 1999-02-04 21:39:01 ODBC - MSAccess W95/98

Browse pgsql-sql by date

  From Date Subject
Next Message Jackson, DeJuan 1999-02-04 22:52:57 RE: [SQL] problem with join & count
Previous Message Dimitri 1999-02-04 22:10:05 Re: [SQL] problem with join & count