pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
return records with more than one occurrences
4+ messages / 4 participants
[nested] [flat]

* return records with more than one occurrences
@ 2011-01-05 14:18 Tarsis Lima <tarsis.lima@gmail.com>
  2011-01-07 10:07 ` Re: return records with more than one occurrences Jasmin Dizdarevic <jasmin.dizdarevic@gmail.com>
  2011-01-07 11:04 ` Re: return records with more than one occurrences Oliveiros d'Azevedo Cristina <oliveiros.cristina@marktest.pt>
  2011-01-08 04:48 ` Re: return records with more than one occurrences Russell Galyon <russellgalyon@gmail.com>
  0 siblings, 3 replies; 4+ messages in thread

From: Tarsis Lima @ 2011-01-05 14:18 UTC (permalink / raw)
  To: pgsql-sql

how would the SELECT to  return only records with more than one
occurrences  of id_table1? example:
 -- Table1
 -- id --
-------------------------
    1
    2


-- Table2
   id  --- | id_table1 | name
  ----------------------------------------------
   4  ---- | -----  1 ------ |   Tom
   5  ---- | -----  1 ------ |   Luci
   6  ---- | -----  2 ------ |  Cleber   ------>this can not return






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

* Re: return records with more than one occurrences
  2011-01-05 14:18 return records with more than one occurrences Tarsis Lima <tarsis.lima@gmail.com>
@ 2011-01-07 10:07 ` Jasmin Dizdarevic <jasmin.dizdarevic@gmail.com>
  2 siblings, 0 replies; 4+ messages in thread

From: Jasmin Dizdarevic @ 2011-01-07 10:07 UTC (permalink / raw)
  To: Tarsis Lima <tarsis.lima@gmail.com>; pgsql-sql

Hi,

this is a good point to start.

select t2.* from table2 t2
inner join (
  select id from table1
  group by id
  having count(*) > 1
) t1 on t2.id_table1 = t1.id

2011/1/5 Tarsis Lima <tarsis.lima@gmail.com>

> how would the SELECT to  return only records with more than one
> occurrences  of id_table1? example:
>  -- Table1
>  -- id --
> -------------------------
>    1
>    2
>
>
> -- Table2
>   id  --- | id_table1 | name
>  ----------------------------------------------
>   4  ---- | -----  1 ------ |   Tom
>   5  ---- | -----  1 ------ |   Luci
>   6  ---- | -----  2 ------ |  Cleber   ------>this can not return
>
>
>
>
> --
> Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-sql
>

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

* Re: return records with more than one occurrences
  2011-01-05 14:18 return records with more than one occurrences Tarsis Lima <tarsis.lima@gmail.com>
@ 2011-01-07 11:04 ` Oliveiros d'Azevedo Cristina <oliveiros.cristina@marktest.pt>
  2 siblings, 0 replies; 4+ messages in thread

From: Oliveiros d'Azevedo Cristina @ 2011-01-07 11:04 UTC (permalink / raw)
  To: Tarsis Lima <tarsis.lima@gmail.com>; pgsql-sql

Howdy, Tarsis.

Please try this out.

SELECT a.id, id_table1,a.name
FROM "Table2" a
NATURAL JOIN 
(SELECT id_table1
"Table2" 
GROUP BY id_table1
HAVING COUNT(*) > 1) b

Tell me if it worked or not, and if it didn't the errors/uncorrect results.

Best,
Oliveiros

----- Original Message ----- 
From: "Tarsis Lima" <tarsis.lima@gmail.com>
To: <pgsql-sql@postgresql.org>
Sent: Wednesday, January 05, 2011 2:18 PM
Subject: [SQL] return records with more than one occurrences


> how would the SELECT to  return only records with more than one
> occurrences  of id_table1? example:
> -- Table1
> -- id --
> -------------------------
>    1
>    2
> 
> 
> -- Table2
>   id  --- | id_table1 | name
>  ----------------------------------------------
>   4  ---- | -----  1 ------ |   Tom
>   5  ---- | -----  1 ------ |   Luci
>   6  ---- | -----  2 ------ |  Cleber   ------>this can not return
> 
> 
> 
> 
> -- 
> Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-sql



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

* Re: return records with more than one occurrences
  2011-01-05 14:18 return records with more than one occurrences Tarsis Lima <tarsis.lima@gmail.com>
@ 2011-01-08 04:48 ` Russell Galyon <russellgalyon@gmail.com>
  2 siblings, 0 replies; 4+ messages in thread

From: Russell Galyon @ 2011-01-08 04:48 UTC (permalink / raw)
  To: Tarsis Lima <tarsis.lima@gmail.com>; pgsql-sql

SELECT
   t.id
   t.id_table1
   t.name
FROM
   Table2 t
INNER JOIN
   (SELECT
      t_inner.id_table1
   FROM
      Table2 t_inner
   GROUP BY 1
   HAVING COUNT(*) > 1) temp
ON temp.id_table1 = t.id_table1
;

On Wed, Jan 5, 2011 at 8:18 AM, Tarsis Lima <tarsis.lima@gmail.com> wrote:

> how would the SELECT to  return only records with more than one
> occurrences  of id_table1? example:
>  -- Table1
>  -- id --
> -------------------------
>    1
>    2
>
>
> -- Table2
>   id  --- | id_table1 | name
>  ----------------------------------------------
>   4  ---- | -----  1 ------ |   Tom
>   5  ---- | -----  1 ------ |   Luci
>   6  ---- | -----  2 ------ |  Cleber   ------>this can not return
>
>
>
>
> --
> Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-sql
>

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


end of thread, other threads:[~2011-01-08 04:48 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2011-01-05 14:18 return records with more than one occurrences Tarsis Lima <tarsis.lima@gmail.com>
2011-01-07 10:07 ` Jasmin Dizdarevic <jasmin.dizdarevic@gmail.com>
2011-01-07 11:04 ` Oliveiros d'Azevedo Cristina <oliveiros.cristina@marktest.pt>
2011-01-08 04:48 ` Russell Galyon <russellgalyon@gmail.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