Select "Difference from table" - "Two columns" There are no columns that should have a repeat

How to make a choice for table A, for example, containing these records.

|Column1|Column2|
| A      |F     |
| A      | G    |
| B      |G     |
| B      |H     |
| C      |H     |
| D      |H     |
| E      |I     |

Expected Result:

|Column1 |Column2|
| A      | F     |
| B      | G     |
| C      | H     |
| E      | I     |

All columns must have a unique value in them.

What query statement can I use for this?

thanks

+4
source share
3 answers

Try:

select 
    MIN(Column1) Column1, 
    Column2 
from(
    select 
        Column1, 
        MIN(Column2) Column2 
    from YourTable
    group by Column1 
)x group by Column2
order by 1

SQL Fiddle Demo

+1
source

This did not work for this scenario.

create table YourTable (Column1 varchar2(10), 
                        Column2 varchar2(10));

insert into YourTable values ('B','F');
insert into YourTable values ('B','G');
insert into YourTable values ('B','H');
insert into YourTable values ('C','F');
insert into YourTable values ('C','G');
insert into YourTable values ('C','H');
insert into YourTable values ('D','F');
insert into YourTable values ('D','G');
insert into YourTable values ('D','H');

My expectation

BF CG DH

but i just got

Bf

Thanks a lot!

+1
source
SELECT a.val, b.val FROM
(
 SELECT val, rownum as rno 
  FROM
  (
   SELECT distinct column1 as val
     FROM YourTable 
  )) a,
  (
   SELECT val, rownum as rno 
     FROM
  (
    SELECT distinct column2 as val
      FROM YourTable 
  )) b
  WHERE a.rno = b.rno
  ORDER BY 1
  /

VAL VAL_1
-----------
 B  F
 C  G
 D  H

OR

select column1 as val from YourTable 
UNION
select column2 from YourTable 

VAL
-----
B
C
D
F
G
H
+1
source

All Articles