L
Lots_of_Queries
Hi,
I'm still a relative SQL newbie so apologies if this is mundane.
I'm having trouble filtering records using results from aggregate functions.
Specifically I'm trying to find the current names for my customers.
My table is:
seq_n cust_id name effective_dt
1 1 Robert 1970
2 2 Elizabeth 2000
3 1 Bob 1990
4 1 Rob 1990
5 2 Beth 1972
Seq_n is the name sequence number/primary key
cust_id is the id for each customer
name is the possible names
effective_dt is the date from which a given name becomes effective.
For each cust_id I want to find the most recent effective date, then from
this group use the name with the highest seq_n.
i.e.
cust_id name
1 Rob
2 Elizabeth
I'm not sure the best way to acheive this with SQL & would appreciate your
suggestions.
I have been able to do this using a very messy function with several dmax
calls in a 'where' clause but suspect there is a better way using SQL. I'd
also rather not use VBA if possible.
Thanks for your help!
I'm still a relative SQL newbie so apologies if this is mundane.
I'm having trouble filtering records using results from aggregate functions.
Specifically I'm trying to find the current names for my customers.
My table is:
seq_n cust_id name effective_dt
1 1 Robert 1970
2 2 Elizabeth 2000
3 1 Bob 1990
4 1 Rob 1990
5 2 Beth 1972
Seq_n is the name sequence number/primary key
cust_id is the id for each customer
name is the possible names
effective_dt is the date from which a given name becomes effective.
For each cust_id I want to find the most recent effective date, then from
this group use the name with the highest seq_n.
i.e.
cust_id name
1 Rob
2 Elizabeth
I'm not sure the best way to acheive this with SQL & would appreciate your
suggestions.
I have been able to do this using a very messy function with several dmax
calls in a 'where' clause but suspect there is a better way using SQL. I'd
also rather not use VBA if possible.
Thanks for your help!