Forum Discussion

navya942's avatar
navya942
Copper Contributor
Jun 21, 2024

sql query realted to null and not null values in a temp table

Hi all,

1.This is my table from that I have to select that not null values of ID1 and ID3, also select NULL value of ID2 and ID4 not null value.

2. If ID1,ID3 having both NULL and NOT NULL values means  show all NOT NULL values.

3. ID2 having NULL values means show that NULL value of ID2.

4.ID 4 has NOT NULL value  means show that ID4  NOT NULL value .

if the records have similar columns then take not null values, no similar take whether null or not null

 output should be like this :

 

can anyone please help me with this, Thanks in advance!!

 

  • olafhelper's avatar
    olafhelper
    Bronze Contributor

    navya942 , for me that looks more like trash data.

    This query will give you a result, but I am not sure, if that is what you want:

    SELECT T.colA, T.colB, T.colC, MAX(T.colD) AS ColDMax
    FROM yourTable AS T
    GROUP BY T.colA, T.colB, T.colC

     

Resources