Part 75: Subqueries in the SELECT Clause

Part 75 Technology Updated September 12, 2026

Part 75: Subqueries in the SELECT Clause

Placing scalar subqueries directly in the projection list.


1. Syntax

SELECT 
  c.id,
  c.name,
  (SELECT COUNT(*) FROM orders o WHERE o.customer_id = c.id) AS order_count,
  (SELECT MAX(o.total_amount) FROM orders o WHERE o.customer_id = c.id) AS max_order
FROM customers c;

Key Takeaways

  • Keep select subqueries small and indexed to prevent sluggish execution.

In Part 76, we explore Subqueries in the FROM Clause (Derived Tables)!