I have two tables and I want to return a set of data from both the tables that look like this:Account tableAccount char(10)Account_date_time datetimeaccount_set char(2)account_status charCustomer tableAccount char(10)Account_date_time datetimeaccount_type char (2)The data looks like thisAccount tableaccount account_date_time account set account status1111111111 2001-08-15 1 A1111111111 2001-07-15 1 A1111111111 2001-09-15 2 A1111111111 2001-06-15 1 C1111111111 2001-05-15 1 ACustomer tableaccount account_date_time account type1111111111 2001-08-15 T 1111111111 2001-07-15 T 1111111111 2001-09-15 T 1111111111 2001-06-15 T 1111111111 2001-05-15 S
Account and account_date_time are unique keys and have a one to one relationship between the two tables. I want to get all fields from both tables for only the records with the highest account_data_time and an account status of A for each distinct account set. Grouping by account set is a new condition. I am currently using the following slelct statement to fill a cursor.select A.ACCOUNT_NUMBER, A.ACCOUNT_DATE_TIME, C.ACCOUNT_TYPE, A.ACCOUNT_SET from ACCOUNT Ajoin CUSTOMER C on A.ACCOUNT_NUMBER = C.ACCOUNT_NUMBER and C.ACCOUNT_DATE_TIME = A.ACCOUNT_DATE_TIMEwhere A.ACCOUNT_DATE_TIME = (select max(ACCOUNT_DATE_TIME) from ACCOUNT where ACCOUNT_NUMBER = C.ACCOUNT_NUMBER)and C.ACCOUNT_DATE_TIME is not nullThe data I'm getting back now is account account_date_time account type account set1111111111 2001-09-15 T 2
What I want is this account account_date_time account type account set1111111111 2001-08-15 T 11111111111 2001-09-15 T 2
I'm just not getting it today, any thoughts?CatEdited by - cat_jesus on 09/06/2001 10:55:45