I'm trying to return all columns in a database where certain rows within certain columns have been eliminate. Is there any possible way to do this? I tried using code like this but I'm unsure what I am missing to make this work
Select * from table1
where (select column1 from table1
minus select column1 from table2);
You can do this with a WHERE NOT EXISTS
:
Select T1.*
From Table1 T1
Where Not Exists
(
Select *
From Table2 T2
Where T2.Column1 = T1.Column1
)
Alternatively, you could use a LEFT OUTER JOIN
:
Select T1.*
From Table1 T1
Left Join Table2 T2 On T2.Column1 = T1.Column1
Where T2.Column1 Is Null
Or even a WHERE NOT IN
:
Select *
From Table1
Where Column1 Not In
(
Select Column1
From Table2
)
I would recommend the WHERE NOT EXISTS
approach, but to fix the query you have in the question, you just need to add a WHERE IN
:
Select *
From Table1
Where Column1 In
(
Select Column1
From Table1
Minus
Select Column1
From Table2
)
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments