The SubQuery

A SubQuery is a SELECT query that's nested inside a top-level SELECT, DELETE, UPDATE or INSERT statement, a HAVING or WHERE clause, or inside another SubQuery. A SubQuery must be constructed so it only will return a single value. Otherwise you will get an error because it is executed for each row returned in the result set and one row cannot have multiple values for one field. The following example contains a SubQuery that will be used to select all the rows from the Products table that are supplied by Exotic Liquids:

1: SELECT *
2: FROM Products
3: WHERE SupplierID =
4: (SELECT SupplierID FROM Suppliers
5: WHERE CompanyName = 'Exotic Liquids')

Essentially, you're doing a SELECT statement that will retrieve all fields from the ...

Get Programming Data-Driven Web Applications with ASP.NET now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.