Kimberly writes "I love your site. Here is a problem I believe this is a totally impossible problem to solve without resolving to temp tables or use of a cursor. Can you confirm? Here is the select problem I have been trying (unsuccessfully) to solve using subqueries:I have a table CUSTOMERS_ORDER_T containing ID_CUSTOMER and ID_ORDER. Customers exist on this table with mutliple orders, and orders exist on this table with multiple customers. Here is a sample:ID_CUSTOMER ID_ORDER1 11 22 12 3
I also have a table ORDERS_T containing ID_ORDER and DTE_ORDER_FUFILLEDID_ORDER DTE_ORDER_FUFILLED 1 1997 2 19953 1999
Now here is what I need: I want a list of each customer along with the ID_ORDER for thier most recently fufilled order. For Example: ID_CUSTOMER ID_ORDER 1 12 3
I have tried nesting subqueries to find the max DTE_ORDER_FUFILLED, but I can't get it to work in a corrolated fashion returning one row per ID_CUSTOMER. I can only get it to return the max date for the whole ID_ORDER table. If I play with it I am warned that I cannot have an aggregate function in a WHERE clause, that I must instead put it in the HAVING clause, but I'm not having much luck with that either. I hope you can figure this one out!"