directormac
Occasional Presence
- Local time
- Today, 20:44
- Joined
- Oct 24, 2001
- Messages
- 259
Happy whatever you celebrate to everyone! With the quiet holiday weeks I've been making long overdue progress on my EAV-based project, in fact I was hoping to post it for feedback soon, but I realized today I was making a simple mistake somewhere and apparently I've looked at it too many times to be able to solve it.
This isn't directly EAV-related, so here's a simplified version.
Say you're relating many-to-many by way of a joining table. Not even complicated. A list of diners and a list of restaurants and a joining table that records which diner visited which restaurant on what date:
Now suppose you want to see a list of all diners, with all the restaurants they've been to, but ONLY the MOST RECENT visit to any given restaurant. So you need only the most recent value of dtmVisitDate for all unique lngDinerID-lngRestaurantID pairs. Such that this list:
Would look nearly the same, but record #1 (Fred/Sonic/Jan 1) would be absent because Fred went to Sonic again on Nov 11.
I can get the right rows if I use a distinct select, but then I lose the autoDinersToRestaurantsKEY field:
Or I can get all the fields but with duplicate rows. And, try as I might, I can't write a union off the first version that gives me the right results either. I know I'm forgetting something simple, I just don't know what it is. Obvs. Searching brings me plenty of results for getting what I'm already getting (latest date value but without bringing in non-grouped fields).
PLEASE NOTE: Because of my work situation, I CANNOT download files. I know that makes it a pain to help me, I apologize.
Example attached.
This isn't directly EAV-related, so here's a simplified version.
Say you're relating many-to-many by way of a joining table. Not even complicated. A list of diners and a list of restaurants and a joining table that records which diner visited which restaurant on what date:
Now suppose you want to see a list of all diners, with all the restaurants they've been to, but ONLY the MOST RECENT visit to any given restaurant. So you need only the most recent value of dtmVisitDate for all unique lngDinerID-lngRestaurantID pairs. Such that this list:
Would look nearly the same, but record #1 (Fred/Sonic/Jan 1) would be absent because Fred went to Sonic again on Nov 11.
I can get the right rows if I use a distinct select, but then I lose the autoDinersToRestaurantsKEY field:
Code:
SELECT lngDinerID, lngRestaurantID, MAX(dtmVisitDate) AS dtmMostRecentMeal
FROM tblDinersToRestaurants
GROUP BY lngDinerID, lngRestaurantID
ORDER BY lngDinerID, lngRestaurantID;
Or I can get all the fields but with duplicate rows. And, try as I might, I can't write a union off the first version that gives me the right results either. I know I'm forgetting something simple, I just don't know what it is. Obvs. Searching brings me plenty of results for getting what I'm already getting (latest date value but without bringing in non-grouped fields).
PLEASE NOTE: Because of my work situation, I CANNOT download files. I know that makes it a pain to help me, I apologize.
Example attached.