Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Oracle: Get All Rows Except One

I am stuck with a simple query. What i want is to get all rows except one Kindly have a look at the following data.

COL_A   COL_B
B       D
B       (null)
B       C
G       D
G       (null)
G       C

I want to get all rows except but B C. Kindly have a look at the sqlfiddle

I have tried to get the rows by anding col_A <> 'B' and col_B <> 'C' but it's not anding the operation. Your help will be much appreciated.

Thanks

like image 961
Zeb-ur-Rehman Avatar asked Sep 28 '22 03:09

Zeb-ur-Rehman


2 Answers

One possible solution. Maybe not the most elegant:

select req_for col_A, doc_typ col_B 
from a
where (req_for IS NULL OR doc_typ IS NULL) 
OR (req_for,doc_typ) 
NOT IN (select 'B','C' from dual);
like image 93
user2672165 Avatar answered Nov 15 '22 11:11

user2672165


Try

where not(col_A = 'B' and col_B = 'C')

or

where col_A <> 'B' or col_B <> 'C'
like image 36
vc 74 Avatar answered Nov 15 '22 11:11

vc 74