I am trying to achieve the following but not able to
Id CatID CategoryName
-------------------------
1 1 Movies
2 1 Movies
3 2 Books
4 3 Tools
What I am trying to achieve is :
I want all the records :
Output :
Id CatID CategoryName
-------------------------
3 2 Books
4 3 Tools
You can use not exists
:
select t.*
from mytable t
where not exists (
select 1 from mytable t1 where t1.catID = t.catID and t1.id = 1
)
For performance with this query, consider an index on (catID, id)
.