Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Keeping the column data order after using (distinct/group by)

sgalaxySep 3 2015 — edited Sep 3 2015

Hi,

Supposing there is a simple data set as:

select 6 from dual union all

select 2 from dual union all

select 12 from dual union all

select 8 from dual union all

select 6 from dual

When i apply either distinct or group by the initial data set order is not kept.

with sample_data(data) as

(select 6 from dual union all

select 2 from dual union all

select 12 from dual union all

select 8 from dual union all

select 6 from dual)

select  distinct data

    from sample_data

    -- group by data  -- the same, the initial set order is not kept

How to keep the initial data set order leaving out the duplicate values?

In other words, the order should be:

6, 2, 12, 8

and not

6, 2, 8, 12

Db version: 11g v2

Thanks a lot,

Sim

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 1 2015
Added on Sep 3 2015
12 comments
2,131 views