Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query Top 3 dates for each KEY

Status
Not open for further replies.

ETID

Programmer
Jul 6, 2001
1,867
US
Hi,

I have a table of multiple comments called "comments", each comment has a date, each date & comment combination is related to a master table by 4 KEY fields,...

I.E.

|--------KEY FIELDS---------|
| KEY1 | KEY2 | KEY3 | KEY4 | Date | Comment

How do I query just the comments table and get the most recent 3 comments (by date) for each record KEY?


Thanks,
 
Having 4 fields creating a primary key makes for lots of extra work. I always use a single key. If you had a single field, your query might look like:
SELECT *
FROM tblA
WHERE PriKey IN
(SELECT TOP 3 PriKey
FROM tblA A
WHERE tblA.GroupKey = A.GroupKey
ORDER BY DateField DESC);

Also, Date is a function so you should avoid using Date as a field name.

Duane
MS Access MVP
Find out how to get great answers faq219-2884.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top