A subquery in SQL is a query inside a query and it is used to retrieve data from multiple tables or to perform aggregate functions in a single query. In a correlated subquery, the inner query depends on the outer query to run.
Here is how to use a correlated subquery to return one row per customer, representing the customer’s oldest order (the one with the earliest date). Each row should include these three columns: email_address, oldest_order_id, and oldest_order_date. Sort the result set by the oldest_order_date and oldest_order_id columns:SELECT c.email_address, o.oldest_order_id, o.oldest_order_dateFROM customers c, orders oWHERE c.customer_id = o.customer_idAND o.order_date = (SELECT MIN(order_date)FROM orders o2WHERE o2.customer_id = o.customer_id)ORDER BY o.oldest_order_date, o.oldest_order_id;In the above query, we use a correlated subquery to return the oldest order for each customer.
The outer query joins the customers and orders tables on the customer_id column. The inner query selects the minimum order_date for each customer using the correlated subquery. This query returns one row per customer with the customer’s oldest order (the one with the earliest date). We then sort the result set by the oldest_order_date and oldest_order_id columns.
To know more about SQL visit:
brainly.com/question/31663284
#SPJ11