In this post, we want to discuss about a nice function to use multiple columns for NOT IN in SQL Server. Before we get started, if you want to know about random number generator, please go through the following article: Random Number Generator Script – SQL Query.
Let’s Start. I want to select all records from a table FRIEND where the values in columns f1 and f2 has no matching tuple for the columns l1 and l2 in table LIKES.
SELECT * FROM FRIEND F
WHERE not exists
SELECT 1 FROM LIKES L WHERE F.f1 = L.l1 and F.f2 = L.l2