Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

tSQL NOT IN Query

I want to get the ID's of [interactions] table but these ID's must not equal to [EmailOUT] table. I couldn't write the query.

Select ID from EmailOut         
where ID NOT IN         
   (select ID from
    [172.28.101.120].[GenesysIS].dbo.interactions 
    where media_type = 'email'
    and type = 'Outbound')

something similar to this. I want Outbound Emails in Interactions table but these emails may exist in EmailOut table. I want to remove them. Outbound Email count about 300 but this query result should less than 300

like image 545
cihadakt Avatar asked May 28 '13 06:05

cihadakt


People also ask

How use not in condition in SQL query?

Scenario: Get the price of the product where the supplier is not ABC. Query: SELECT ProductPrice FROM Product WHERE ProductName NOT IN (SELECT ProductName FROM Supplier WHERE SupplierName = "ABC"); That's all for SQL IN and SQL NOT IN operator examples.

WHERE not exists in SQL query?

SQL NOT EXISTS in a subqueryNOT EXISTS is used with a subquery in the WHERE clause to check if the result of the subquery returns TRUE or FALSE. The Boolean value is then used to narrow down the rows from the outer select statement.

Can we use in and not in in SQL query?

IN, NOT IN operators in SQL are used with SELECT, UPDATE and DELETE statements/queries to select, update and delete only particular records in a table those meet the condition given in WHERE clause and conditions given in IN, NOT IN operators. I.e. it filters records from a table as per the condition.

Is not and != In SQL?

SQL Not Equal (<>) Operator In SQL, not equal operator is used to check whether two expressions are equal or not. If it's not equal, then the condition will be true, and it will return not matched records. Both != and <> operators are not equal operators and will return the same result, but the !=


1 Answers

It seems you should reverse your query, if you want to get the ID's of [interactions] table:

select ID from
[172.28.101.120].[GenesysIS].dbo.interactions 
where media_type = 'email'
and type = 'Outbound'
AND ID NOT IN (SELECT ID FROM EmailOut)
like image 144
Andrey Gordeev Avatar answered Sep 19 '22 09:09

Andrey Gordeev