return records with more than one occurrences
return records with more than one occurrences
От:
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
Re: return records with more than one occurrences
От:
Jasmin Dizdarevic <jasmin.dizdarevic@gmail.com>
Дата:
Hi,
this is a good point to start.
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
Re: return records with more than one occurrences
От:
"Oliveiros d'Azevedo Cristina" <oliveiros.cristina@marktest.pt>
Дата:
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" To: 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
Re: return records with more than one occurrences
От:
Russell Galyon <russellgalyon@gmail.com>
Дата:
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
;
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