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

getting most recent record

Status
Not open for further replies.

ashiers

Programmer
Jun 17, 2005
4
CA
Hi there,

Given a table that has the following fields:

create table WAGE_RATES(
EMPLOYEE_ID int unsigned references EMPLOYEES,
DATE date,
HOURLY float(5,2),
WEEKLY float(5,2),
OTHER float(5,2),
index(DATE)
);

I want to run a SELECT query that uses the EMPLOYEE_ID number to compare all available records and return only the most recently entered record making use of the DATE field. What does the query look like? How do you make the database return a record based on the most recent date?

Alan
 
Something like
Code:
SELECT * FROM WAGE_RATES ORDER BY DATE DESC LIMIT 1
should give you an idea of how to implement your query

Andrew
Hampshire, UK
 
if you want the latest row per employee,
Code:
select EMPLOYEE_ID
     , `DATE`
     , HOURLY 
     , WEEKLY 
     , OTHER
  from WAGE_RATES as W
 where `DATE`
     = ( select max(`DATE`)
           from WAGE_RATES 
          where EMPLOYEE_ID 
              = W.EMPLOYEE_ID )

r937.com | rudy.ca
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top