两列的不同值

时间:2016-06-21 05:41:20

标签: sql

这是我用来获取不同值的查询:

SELECT DISTINCT
    LOGIN_BY,
    RECEIVED_BY
FROM SAMPLE

我的要求是我需要将两列的不同值作为单个输出。有没有办法做到这一点?

2 个答案:

答案 0 :(得分:0)

试试这个

(SELECT DISTINCT LOGIN_BY as ID from sample )
union all
(Select Distinct RECEIVED_BY as ID FROM SAMPLE)

答案 1 :(得分:0)

试试这样:

select distinct a from (
  select
    distinct LOGIN_BY as a
  from
    SAMPLE
  union
  select
    distinct RECEIVED_BY as a
  from
    SAMPLE
);

这适用于Oracle数据库。