Finding the max date

roshanstevv

Member
Joined
Feb 8, 2007
Messages
12
Programming Experience
1-3
hi,
i have a database where there is 10 feilds one of which is of datetime

I have to select a row from the table which has two search Conditions
Frist i have to select from the table who has ( say GroupId =1) and From these rows( whose GroupId=1) I have to select at the row that is last entered Max(Date)
Thanks InAdvance
 
select max(date) from yourtable where groupid = 1

-tg
 
TG's query gives you the most recent date for groupid 1.

This query additionally gives you all the row data:

SELECT * FROM yourtable WHERE groupid = 1 AND date = (select max(date) from yourtable where groupid = 1)


If groupid and date are not the primary key, you are strongly advised to include all columns of the primary key in the WHERE clauses.

On an unrelated note, do not call a column "Date" - be more specific and stay way from data types for names. Call it employDate or birthDate or soemthing
 
Back
Top