Skip to content
Advertisement

SQL query to exclude records that already mapped with another column id and show rest to them

I am trying to achieve the following but not able to

What I am trying to achieve is :

I want all the records :

  1. not having ID as 1 and
  2. Exclude (CatID) records that ID = 1 is sharing with other IDs. In this case Id =1 and Id = 2 sharing the same CATID= 1 (Movies). I want to eliminate such records and show the rest of them.

Output :

Advertisement

Answer

You can use not exists:

For performance with this query, consider an index on (catID, id).

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement