Question: I had tried using the the below query but couldn't retrive the distinct values of the column `status_id`. 

```
select distinct status_id, schedule_id, cassay_id, time_of_day,
                days, notify_to_addresses, active FROM ordertest

```

The purpose of the the above query is to filter the table to get the unique value of the column '`status_id`' at the same time it needs to fetch values for all columns present in the table. So that my final table will consist of the distinct values of `status_id` and their corresponding other values.

Answer: 
This query *will* return unique status\_id's, but only if the combination of those status\_id and each of those other fields is unique too. You can select the unique status\_id's, but you cannot return all values of the other fields if there's more than one combination for each status\_id.

[edit]

If you want only the first record for each status:

```
select 
  status_id, schedule_id, cassay_id, time_of_day, days, notify_to_addresses, active 
from
  (select 
    row_number() over (partition by status_id order by 1) as number, 
    status_id, schedule_id, cassay_id, time_of_day, days, notify_to_addresses, active 
  FROM ordertest)
where
  number = 1

```

Instead of `row_number`, `dense_rank` and `rank` are used as well for different kinds of numbering, but in this case you really do want a single row, and row\_number will suffice.

Not sure `order by` is mandatory. If not, you can leave it out. If it is, you can specify a dummy value or specify a specific field that you want to use as 'the first row'. For example, spedify `order by schedule_id` to return the lowest schedule\_id for each status\_id.
`DISTINCT` works for each row, other fields are not same for all distinct `status_id`, so you can not use DISTINCT.

Use `GROUP BY`, and use Group functions (`MAX,MIN,WM_CONCAT` **WHAT YOU NEED**) for other Columns.

OR use `subqueries` by `primary key` for each column.