D
doyle60
This is a bit confusing so let me give an example. If I have the
following data in a table:
PO Style Date Store
100012 2012 10/31/05 Adam's
100012 2012 10/15/05 Zac's
100012 2012 12/10/06 Ralph's
100012 2012 12/10/06 Pete's
100015 3333 02/31/07 Macy's Co.
100015 3333 03/15/07 Bloomingdales
100015 3333 03/18/07 Joe's Tavern
how do I get it to return the style with the latest date and give me a
store that actually corresponds to that date? So, I want it to
return:
100012 2012 12/10/06 Ralph's
100012 2012 12/10/06 Pete's
100015 3333 03/18/07 Joe's Tavern
If there is a tie on the store (as Ralph's and Pete's is above), I
will take both.
You see, if I simply choose in the query to give the max date and the
max or min or first or last Store, I could end up with a mismatch. So
choosing last store with a max date gives this:
100012 2012 12/10/06 Zac's
100015 3333 03/18/07 Macy's Co.
Both of which are mismatches. Zac's never corresponds with 12/10/06.
I know how to do this in multiple queries and have been doing it for
years. But I thought there may be a way to do it in ONE query. Is
there?
Thanks,
Matt
following data in a table:
PO Style Date Store
100012 2012 10/31/05 Adam's
100012 2012 10/15/05 Zac's
100012 2012 12/10/06 Ralph's
100012 2012 12/10/06 Pete's
100015 3333 02/31/07 Macy's Co.
100015 3333 03/15/07 Bloomingdales
100015 3333 03/18/07 Joe's Tavern
how do I get it to return the style with the latest date and give me a
store that actually corresponds to that date? So, I want it to
return:
100012 2012 12/10/06 Ralph's
100012 2012 12/10/06 Pete's
100015 3333 03/18/07 Joe's Tavern
If there is a tie on the store (as Ralph's and Pete's is above), I
will take both.
You see, if I simply choose in the query to give the max date and the
max or min or first or last Store, I could end up with a mismatch. So
choosing last store with a max date gives this:
100012 2012 12/10/06 Zac's
100015 3333 03/18/07 Macy's Co.
Both of which are mismatches. Zac's never corresponds with 12/10/06.
I know how to do this in multiple queries and have been doing it for
years. But I thought there may be a way to do it in ONE query. Is
there?
Thanks,
Matt