Engineering/Database
How Subqueries and CTEs Work in SQL
As SQL queries become more complex, a single table is often not enough to produce the result we need.Suppose we want to answer the following question:Which orders have a total amount greater than the average order amount?Before identifying those orders, the database must first calculate the average.SELECT AVG(total_amount)FROM orders;It must then compare each order with that value.SQL allows us ..