Quantcast
Channel: Teradata Forums - Database
Viewing all articles
Browse latest Browse all 14773

Distinct Logic - response (3) by M.Saeed Khurram

$
0
0

Hi Bikky,
Hope the following query will dolve your problem, Or at least give you a start.

CT TD3471.table1(name1 VARCHAR(10),name2 VARCHAR(10));
INS INTO TD3471.table1 VALUES('ABC','XYZ');
INS INTO TD3471.table1 VALUES('ABC','ABC');
INS INTO TD3471.table1 VALUES('XYZ','DEF');
INS INTO TD3471.table1 VALUES('ABC','DEF');
INS INTO TD3471.table1 VALUES('GHI','DEF');

SELECT * FROM TD3471.table1;

SELECT  DISTINCT NAMES,
CASE WHEN A.NAME1 IS NULL THEN 'N' ELSE 'Y' END AS NAME1
,CASE WHEN B.NAME2 IS NULL THEN 'N' ELSE 'Y' END AS NAME2
FROM
(
SELECT NAME1 AS NAMES
FROM TD3471.table1
UNION
SELECT NAME2 AS NAMES
FROM TD3471.table1
)AS DRV
LEFT JOIN TD3471.table1 A
ON DRV.NAMES = A.NAME1
LEFT JOIN TD3471.table1 B
ON DRV.NAMES = B.NAME2;

 


Viewing all articles
Browse latest Browse all 14773

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>