Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to filter null value in Oracle sql

I want to filter the records that COMMENTS attribute is null

enter image description here

I have tried

SELECT TABLE_NAME, COMMENTS FROM 
    (SELECT TABLE_NAME, COMMENTS FROM (select * FROM user_tab_comments))
    WHERE COMMENTS != null;

But it didn't return the right output. How can I do it?

like image 434
GoingMyWay Avatar asked Apr 29 '26 09:04

GoingMyWay


1 Answers

NULL is a state not a value, therefore you can't use normal operators on it. Use IS NULL or IS NOT NULL instead.

SELECT TABLE_NAME, COMMENTS 
  FROM (SELECT TABLE_NAME, COMMENTS FROM (select * FROM user_tab_comments))
    WHERE COMMENTS IS NOT NULL;

Just saw that you don't need all those subqueries

SELECT TABLE_NAME, COMMENTS 
  FROM user_tab_comments 
 WHERE COMMENTS IS NOT NULL;
like image 68
Jorge Campos Avatar answered May 02 '26 14:05

Jorge Campos



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!