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

max date less than current

Status
Not open for further replies.

sbarlow

MIS
May 29, 2001
2
0
0
US
I currently have a table that contain a list of salary numbers and dates. Each salary number has more than one date. I need to get a table containg salary number, *date, and max date less than *date. So far have been unable to achieve this, Please Help.
 
Hiya,

The command is very simple:

SELECT a.field1, a.field2
FROM table a
WHERE *DATE = (SELECT MAX(*DATE)
FROM table b
WHERE b.primary_key = a.primary_key)

The substitute the field names that you want into the first select statement, and into the where clause of the subquery, change primary_key to whatever field is your unique reference (e.g. employee id etc.)

HTH

Tim
 
How about

QueryOne
Select Salary, Date from Table Where Date < *Date

QueryTwo
Select Salary, max(Date) from QueryOne




Paul
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top