How to get only one record for each duplicate rows of the id in oracle?
SELECT group_id, image, image_id
FROM a_table
WHERE (group_id, image_id) IN
(
SELECT group_id, MIN(image_id)
FROM a_table
GROUP BY
group_id
)
;
There are no standard aggregate functions in Oracle that would work with BLOB
s, so GROUP BY
solutions won't work.
Try this one based on ROW_NUMBER()
in a sub-query.
SELECT inn.group_id, inn.image, inn.image_id
FROM
(
SELECT t.group_id, t.image, t.image_id,
ROW_NUMBER() OVER (PARTITION BY t.group_id ORDER BY t.image_id) num
FROM theTable t
) inn
WHERE inn.num = 1;
The above should return the first (based on image_id
) row for each group.
SQL Fiddle