Search code examples
sqlselectsubquerysql-in

Can you have more than one subquery in a where clause?


I don't have an example for this but I was just wondering if something like this is valid in any situation:

SELECT somefield
FROM sometable
WHERE something1 IN (SELECT somefield2 FROM sometable2)
  AND something2 IN (SELECT somefield3 FROM sometable3)

Solution

  • Yes. Your syntax needs to be fixed though:

    SELECT somefield
    FROM sometable
    WHERE something1 IN (SELECT somefield2 FROM sometable2)                        
    AND something2 IN (SELECT somefield3 FROM sometable3)