pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
RE: [SQL] problem with join & count
2+ messages / 2 participants
[nested] [flat]

* RE: [SQL] problem with join & count
@ 1999-02-04 21:00 Jackson, DeJuan <djackson@cpsgroup.com>
  1999-02-04 22:14 ` Re: [SQL] problem with join & count Dimitri <dimitri@france.Sun.COM>
  0 siblings, 1 reply; 2+ messages in thread

From: Jackson, DeJuan @ 1999-02-04 21:00 UTC (permalink / raw)
  To: pat@patoche.org; pgsql-sql@postgreSQL.org

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/
> 
> 



^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: [SQL] problem with join & count
  1999-02-04 21:00 RE: [SQL] problem with join & count Jackson, DeJuan <djackson@cpsgroup.com>
@ 1999-02-04 22:14 ` Dimitri <dimitri@france.Sun.COM>
  0 siblings, 0 replies; 2+ messages in thread

From: Dimitri @ 1999-02-04 22:14 UTC (permalink / raw)
  To: Jackson, DeJuan <djackson@cpsgroup.com>; +Cc: pat@patoche.org; pgsql-sql@postgreSQL.org

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
=====================================================



^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~1999-02-04 22:14 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
1999-02-04 21:00 RE: [SQL] problem with join & count Jackson, DeJuan <djackson@cpsgroup.com>
1999-02-04 22:14 ` Dimitri <dimitri@france.Sun.COM>

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