From: Oliveiros d'Azevedo Cristina <oliveiros.cristina@marktest.pt>
To: Tarsis Lima <tarsis.lima@gmail.com>
To: pgsql-sql@postgresql.org
Subject: Re: return records with more than one occurrences
Date: Fri, 7 Jan 2011 11:04:53 -0000
Message-ID: <0FD1E8C83BCC4801952A4DEDE3E9713E@marktestcr.marktest.pt> (raw)
References: <d7cb6a09-b376-4e46-ba2b-3dfe82a90d77@c2g2000yqc.googlegroups.com>
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: oliveiros.cristina@marktest.pt, tarsis.lima@gmail.com
Subject: Re: return records with more than one occurrences
In-Reply-To: <0FD1E8C83BCC4801952A4DEDE3E9713E@marktestcr.marktest.pt>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
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