Dear Carol:
Sure.
You've dropped the aliasing. Must have:
SELECT T.vendor, T.[PFG#], T.[start date], T.Price,
T.[end date], T.open, T.[open date], T.[contract sent],
T.[contract recd], T.FOB,
(SELECT COUNT(*) from [item pricing1] T1
where T1.[pfg#] = T.[pfg#]
AND T1.[start date] > T.[start date]) as rank
FROM [Item Pricing] T
ORDER BY VENDOR, [PFG#], [start date] DESC
Now, the fact that you've added vendor to the sort makes me
suspicious. I'll be you want the ranking by vendor and PFG#. If so,
here's the change:
SELECT T.vendor, T.[PFG#], T.[start date], T.Price,
T.[end date], T.open, T.[open date], T.[contract sent],
T.[contract recd], T.FOB,
(SELECT COUNT(*) from [item pricing1] T1
where T1.vendor = T.vendor AND T1.[pfg#] = T.[pfg#]
AND T1.[start date] > T.[start date]) as rank
FROM [Item Pricing] T
ORDER BY VENDOR, [PFG#], [start date] DESC
This changes the "group" from item to vendor and item.
This ranking starts from 0. You can add 1 to it thus:
(SELECT COUNT(*) + 1 from [item pricing1] T1
that is, a small change in the one line.
Hope I've got this right. It's so much easier for you if I can write
the SQL for your exact situation rather than have you try to interpret
code I've written which you may not understand.
For reference, this is a "correlated subquery" - something you may
want to study. Also, check out what an "alias" is.
Tom Ellison
Microsoft Access MVP
Ellison Enterprises - Your One Stop IT Experts
sorry to be such a bother, but i cannot locate the problem
here. can you review my code and tell me what i did wrong
as i followed your code below. i am getting the
message "database engine can't find input table or query
item "item pricing1". my input table is spelled correctly
with a space between the two words. thx.
SELECT [Item Pricing].vendor, [Item Pricing].[PFG#], [Item
Pricing].[start date], [Item Pricing].Price, [Item
Pricing].[end date], [Item Pricing].open, [Item Pricing].
[open date], [Item Pricing].[contract sent], [Item
Pricing].[contract recd], [Item Pricing].FOB,
(SELECT COUNT(*) from [item pricing1] where [item
pricing1].[pfg#] = [item pricing].[pfg#] AND [item
pricing1].[start date] > [item pricing].[start date]) as
rank
FROM [Item Pricing]
ORDER BY VENDOR, [PFG#], [start date] DESC
-----Original Message-----
Dear Carol:
As I did not know the name of your table, I just used YourTable to
refer to it in two places. Both are references to the same table.
Where I used T and T1, these are "aliases" that allow the query to
distinguish between two independent references (instances) to the same
table.
There is no need to change anything, and no two tables involved. Just
substitute you actual column names and your (one) table name (in two
places). Let me know how this does for you.
Tom Ellison
Microsoft Access MVP
Ellison Enterprises - Your One Stop IT Experts
.