Teradata SQL

General

Teradata SQL

HI,

I have a column with both data and a null value for a unique PID .

eg:

PID   VALUE

1       A

1       Null

2       Null

3       Y

I want to populate the data into my report as

PID VALUE

1 A

2 Null

3 Y

Can anyone please help me to get the SQL for eliminating the null value  as specified.

Thanks in advance.

3 REPLIES
Senior Apprentice

Re: Teradata SQL

SELECT PID, MAX(VALUE)
FROM tab
GROUP BY 1;

Re: Teradata SQL

Thanks Dnoeth..Can you suggest ,if its possible to use CASE statement to retrive the the same output.

Senior Apprentice

Re: Teradata SQL

No CASE because you need to work on multiple rows.

If you need additional columns you can utilize ROW_NUMBER:

SELECT *
FROM tab
QUALIFY
ROW_NUMBER()
OVER (PARTITION BY PID ORDER BY VALUE DESC) = 1;