Nesting SELECT statements
Some databases, like Microsoft SQL Server, allow nested SELECT statements, also known as sub-selects.
orders = ( SELECT COUNT(*) FROM orders WHERE orders.contact_id = contacts.id )
This statement will select all contacts and show how many orders they have placed.
The COUNT(*) function is a so called Aggregate function. In this example COUNT(*) will count the number of records.