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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple select question 1

Status
Not open for further replies.

Deam

Programmer
Oct 10, 2000
68
US
I need to take over all the records from a history table which has code,description,StartDate, EndDate fields in it to a new table which has code,description fields in it. I need to take over only the records with the most current dates.

INSERT INTO tNewTable(Code,Description)
SELECT MAX(RequisitionStartDate,
Code,Description FROM tOldTable
GROUP BY Code, Description

does not work cause the new table does not have a StartDate field.

...Thanks in advance
 
Move your MAX(RequisitionStartDate) to your Group by clause petersdaniel@hotmail.com
"If A equals success, then the formula is: A=X+Y+Z. X is work. Y is play. Z is keep your mouth shut." --Albert Einstein

 
Can you try this one (untested):

INSERT INTO tNewTable(Code,Description)
Select Code, Description
from
(
SELECT Code, Description,
MAX(RequisitionStartDate) as Startdate
FROM tOldTable
GROUP BY Code, Description
) as dt

Hopefully, it will do the job for you.
bperry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top