Get First and Last Order per Customer
Orders Table:

Query Explanation:
MIN(OrderDate) gives the first order date for each customer.
MAX(OrderDate) gives the last order date for each customer.
GROUP BY CustomerID ensures we get one row per customer.
SQL Query:
SELECT
CustomerID,
MIN(OrderDate) AS FirstOrderDate,
MAX(OrderDate) AS LastOrderDate
FROM Orders
GROUP BY CustomerID;
Output:

