I have a table with sample1 and sample2 Columns. Some of the sample2 values exist in sample 1. Now I want to extract a table where sample2 value is NOT available in sample1. Please see the tables below for clarification. Thanks.
2 Answers
You can use NOT EXISTS :
SELECT t.*
FROM table t
WHERE NOT EXISTS (SELECT 1 FROM table t1 WHERE t1.sample1 = t.sample2);
1 Comment
Gordon Linoff
@mumid . . .
NOT EXISTS is better with a subquery because it handles NULL values intuitively.You basically said the answer in you question. Make sure Sample2 is NOT IN Sample1
SELECT *
FROM Table
WHERE Sample2 NOT IN (SELECT Sample1 From Table)
2 Comments
VBoka
You are welcome. You have been faster than me and here is a oracle fiddle if you want to attach it: dbfiddle.uk/… cheers
urdearboy
Trying to practice. Answering questions is how I learned my first language so moving onto SQL. I don't know how to use fiddle but will look at what you shared! Super useful
