Search code examples
sqlsubqueryexistscorrelated-subqueryin-clause

I want to convert exist clause into In clause of the following query


SELECT SupplierName
FROM Suppliers
WHERE EXISTS (SELECT ProductName FROM Products 
              WHERE Products.SupplierID = Suppliers.supplierID AND Price < 20);

I want to convert the existing clause into an IN clause of the query.


Solution

  • Here you go:

    SELECT SupplierName
    FROM Suppliers
    WHERE Suppliers.SupplierID IN (
        SELECT Products.SupplierID
        FROM Products 
        WHERE Price < 20
    )