From: | Edson Richter <richter(at)simkorp(dot)com(dot)br> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: Select duplicated values |
Date: | 2011-11-21 22:59:23 |
Message-ID: | 4ECAD7CB.6030503@simkorp.com.br |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
I think you should not "add columns", but concatenate them.
Instead
select A from table_name where B+C+D in (select B+C+D from table_name
group by B+C+D having count(*)>1 )
use "B || '/' || C || '/' || D"
select A from table_name where B || '/' || C || '/' || D in (select B || '/' || C || '/' || D from table_name
group by 1 having count(*)>1 )
You may need to apply some conversion (cast) depending of data type and
output format.
Regards,
*Edson Carlos Ericksson Richter*
/SimKorp Informática Ltda/
Fone: (51) 3366-7964
Celular: (51)9318-9766/(51) 8585-0796
Embedded Image
Em 21-11-2011 20:23, jeffrey escreveu:
> Lets say that the primary key column is A. I am trying to select all
> the rows with duplicated values in columns B, C, and D.
>
> I am not too experienced in SQL syntax, and I've used the following:
> select A from table_name where B+C+D in (select B+C+D from table_name
> group by B+C+D having count(*)>1 )
>
> I'm looking for a better way, since I am just adding the three columns
> together right now.
>
> Jeffrey
>
From | Date | Subject | |
---|---|---|---|
Next Message | Pete Yunker | 2011-11-21 23:19:29 | Re: Select duplicated values |
Previous Message | david.sahagian | 2011-11-21 22:56:42 | successive select statements |