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 records for the date closest to today

Status
Not open for further replies.

amillia

Programmer
Nov 14, 2001
124
US
I have thousands of records. 3 or 4 of each have like serial numbers. Of those 3 or 4 with like serial numbers I need to query out the one with the newest date. How do I do this?
 
more information needed, but you need to look at a select using the group and max function, with either an "exists" or a "in" or a "join"

Regards

Frederico Fonseca
SysSoft Integrated Ltd
 
Another way:
SELECT A.*
FROM yourTable AS A INNER JOIN (
SELECT [serial number], Max([Date]) AS NewestDate
FROM yourTable GROUP BY [serial number]
) AS B ON A.[serial number] = B.[serial number] AND A.[Date] = B.NewestDate

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Okay, I tried this I am getting a syntax error in the FROM clause maybe because I am joining tables also. Here is the query:

SELECT tbl_bld.serial_NO, Tbl_MRPii.WorkCenter, Tbl_MRPii.WoNbr, Tbl_MRPii.OrgCode, Tbl_MRPii.StartDte, tbl_bld.TAT_START_DATE, tbl_bld.LETTER_DISTRIB_DATE, tbl_bld.TEST_POC
FROM tbl_bld as money, Tbl_MRPii as manuf
WHERE (((tbl_bld.TAT_START_DATE)>=10/1/2002) AND ((tbl_bld.LETTER_DISTRIB_DATE) Is Null) AND ((tbl_bld.TEST_POC)='Lori Price')) and (tbl_bld.WORK_ORDER_NUM = Tbl_MRPii.WoNbr) and (Tbl_MRPii.StartDte = (Select max(TBL_MRPii.StartDte) from tbl_MRPii where tbl_bld.cont_no = money.cont_no))
 
Money is a reserved keyword.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top