Yangang Wang Yangang Wang - 1 year ago 94
SQL Question

oracle sql error:distinct case

I am trying to select a distinct column from an oracle database,my code is:

select ID,distinct case when DM='ST1B' then MC else DM end from D_DZDY

but,it does not work.If i remove 'distinct',it works:
enter image description here

Anybody can help me with this problem?thanks a lot! :D

Answer Source

The syntax is select distinct. There is no distinct function or operator on a single column.

Perhaps you intend:

select distinct ID, (case when DM = 'ST1B' then MC else DM end)
from D_DZDY;

This will return distinct pairs of id and the case expression.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download