Hej,
Potrzebuję skasować z bazy danych (PostgreSQL wszystkie rekordy, które są duplikatami, pozostawiając jedynie pierwszy rekord).
Czy takie zapytanie jest ok i czy jest bezpieczne:
DELETE FROM dictionary t
INNER JOIN (
SELECT pm, st_value, MIN(pm) num
FROM dictionary
WHERE fk_dictrelpm = 10000 AND st_value = 'NAGDDPO'
GROUP BY st_value
) t1 ON t.st_value = t1.st_value AND t.num > t1.num AND t1.fk_dictrelpm = 10000 AND t1.st_value = 'NAGDDPO'
WHERE t.fk_dictrelpm = 10000 AND t.st_value = 'NAGDDPO';
?
Struktura mojej tabeli:
create table dic_rel_field
(
pm integer not null,
dv integer not null
constraint dic_rel_field_pk
primary key,
av integer not null,
pr integer not null,
op varchar(50) not null,
wr timestamp not null,
vf timestamp not null,
vt timestamp not null,
fk_dictrelpm integer not null,
fk_dictrelcolpm integer not null,
fk_dictrelrowpm integer not null,
st_value varchar(50)
);