I have a customer table (8 million records or so) and I want to set each customer record with the value of the latest order date from the orders table. I'm in a replication environment, so I don't want to update records needlessly by setting nulls to nulls and dates to the same date. Here's the table layout (vastly simplified);
Here's what I want to to... Update only those customers that have an order on file that is later than the last recorded order date on the Customer table. My attempt fails... well, it updates everything, but it updates EVERYTHING -- not just the records that need updating. (And it generates a bajillion replication messages needlessly.)
I've tried various things to pull the max(order_date) out the subquery to use in a WHERE clause for the customer, but I've had no luck. But somehow, the results of the subquery need to be part of the where clause. Well, unless I scrap the subquery idea and do a JOIN. Any help is appreciated! Using SQLA 9.0.2.3850, replicating via dbremote |
Well, that's one type of problem one might call a SQL Pattern - cf. http://sqlanywhere-forum.sap.com/questions/386/are-there-sql-design-patterns