By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
CREATE TABLE YourTable (
"Id" INTEGER,
"QuestionId" VARCHAR(14)
);
INSERT INTO YourTable
("Id", "QuestionId")
VALUES
('1', 'MyQuestionId'),
('1', NULL),
('2', NULL),
('2', NULL);
4 rows affected
SELECT * FROM YourTable;
Id | QuestionId |
---|---|
1 | MyQuestionId |
1 | null |
2 | null |
2 | null |
WITH cte AS (
SELECT *,
CountNonNulls = COUNT(t.QuestionId) OVER (PARTITION BY t.Id)
FROM YourTable t
)
DELETE cte
WHERE CountNonNulls = 0;
Warning: Null value is eliminated by an aggregate or other SET operation.
2 rows affected
SELECT * FROM YourTable;
Id | QuestionId |
---|---|
1 | MyQuestionId |
1 | null |