I need to generate this output from this db table
— Expected output:
— Neil
— Example case create statement:
CREATE TABLE poll (
id INTEGER NOT NULL PRIMARY KEY,
name VARCHAR(30) NOT NULL,
answer CHAR(1)
);
INSERT INTO poll(id, name, answer) VALUES(1, 'Neil', NULL);
INSERT INTO poll(id, name, answer) VALUES(2, 'Nina', 'Y');
INSERT INTO poll(id, name, answer) VALUES(3, 'Walt', 'N');
I tried to obtain the results using this sql query but does not work
select * from poll where (name like 'N%') AND (answer <> 'N' or answer <> 'Y');
what did I do wrong?
Thx for the support!
>Solution :
Comparing NULL against any string literal will always return false. So, you should also include a null check in your logic:
SELECT *
FROM poll
WHERE name LIKE 'N%' AND
(answer NOT IN ('N', 'Y') OR answer IS NULL);