sarta
Programmer
- Nov 3, 2006
- 29
Say I have a customers table and a history table
I only want to see the latest status for each customer, but this query pulls up EVERY status for each customer:
What is a query that will pull up each customer name, showing the SINGLE latest (most recent) history record for each customer? (Interested in ANSI solution as well as ORACLE 9i)
Code:
CUSTOMERS TABLE
customer_id name
1 Bob
2 Ted
Code:
HISTORY TABLE
history_id customer_id status date
1 1 2 3/1/08
2 1 3 3/4/08
3 1 4 3/2/08
4 2 2 3/1/08
Code:
SELECT customers.name, history.status
FROM customers, history
WHERE customers.customer_id = history.customer_id
What is a query that will pull up each customer name, showing the SINGLE latest (most recent) history record for each customer? (Interested in ANSI solution as well as ORACLE 9i)