Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
SQL where clause for pulling latest date record.
Message
 
 
To
03/04/2006 14:48:13
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
01110024
Message ID:
01110041
Views:
21
This message has been marked as the solution to the initial question of the thread.
There's more than one way to get that result.
Try
SELECT * FROM mytable mt1
 WHERE PostDate = (SELECT MAX(MaxPostDate) FROM mytable mt2
             WHERE mt2.Empid = mt1.Empid )
If you have VFP9
SELECT mt1.* FROM mytable mt1
 JOIN (SELECT Empid, MAX(PostDate) AS MaxPostDate FROM mytable GROUP BY 1) dt2
   ON dt2.Empid = mt1.Empid AND dt2.MaxPostDate = mt1.PostDate
>Looks like that does the trick!!! Thanks so much for your help. I knew there had to be an easy way to do this.
>
>Greg
>
>>Try
>>SELECT * FROM mytable mt1
>> WHERE NOT EXISTS (SELECT * FROM mytable mt2
>>             WHERE mt2.Empid = mt1.Empid AND mt2.PostDate > mt1.PostDate)
>>
>>>
>>>I have data in a file with employee, postdate, and accrued vacation. There is other data in the record that is irrelevent to this query.
>>>
>>>The data looks like this:
>>
>>>Empid      PostDate        Hours
>>>AAB01      01/02/05          40
>>>AAB01      02/02/05          40
>>>AAB01      03/02/05          40
>>>AAB01      04/02/05          80
>>>AAB01      05/02/05          80
>>>BBB01      01/06/05          30
>>>BBB01      02/06/05          30
>>>BBB01      03/06/05          40
>>>BBB01      04/06/05          20
>>>BBB01      05/06/05          20
>>
>>>For my query I always need to get the latest postDate for each employee along with the hours.
>>>
>>>So the result I'm looking for given this data is:
>>>
>>>AAB01 05/02/05 80
>>>BBB01 05/06/05 20
>>>
>>>What would be the best way to handle this type of query?
>>>
>>>
>>>
--sb--
Previous
Reply
Map
View

Click here to load this message in the networking platform