Using a non-correlated subquery in the WHERE clause

This section will help you better understand how to use a non-correlated subquery in the WHERE clause:

  • Using IN: This will return results in the outer query where the results are in the inner query. If the inner query returns even one NULL value, then there will be no outer query results. This is because IN can evaluate to either true, false, or NULL. The IN operator allows you to use a subquery that returns zero or more rows.

You can execute the following query using a non-correlated subquery with IN:

USE lahmansbaseballdb;SELECT playerid, yearid, g as GamesBatted FROM battingWHERE playerid IN (SELECT playerid FROM people WHERE birthcity = 'Boston');

The preceding query returns the ...

Get Learn SQL Database Programming now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.