Microsoft
Software
Hardware
Network
Question : SQL query to select distinct ID for latest date past June/01/2009 where there are (possibly) more than one occurrence of each ID
I have a table with (to keep this simple) two columns : myID and myDate
MyID is NOT unique: that is, the same ID can occur more than once in the MyID field.
MyDate may be blank in some rows
I'm trying to write a query which gives me only the most recent occurence of any ID with an entry in the MyDate field, where the date is greater than June 01, 2009.
So far I've come up with this code.
SELECT DISTINCT(myTable.[MyID]), myTable.[myDate]
FROM
(
SELECT myTable.[myID],MAX(myTable
.[myDate])
AS `latest`
FROM myTable
HAVING myTable.[myDate]>#6/1/2009
#
)
;
Here is my sample table.
myID myDate
123 1/20/2004
123 3/18/2009
123 8/16/2009
123 8/17/2009
221 5/22/2006
229
253
284 10/19/2009
The query should only give me two rows as a result:
123 8/17/2009
284 10/19/2009
Help?
Answer : SQL query to select distinct ID for latest date past June/01/2009 where there are (possibly) more than one occurrence of each ID
also you may add null condition:
select myid, max(mydate) maxdate
from mytable
where mydate > #6/1/2009# and mydate is not null
group by myid
order by myid
Random Solutions
SQL SPLIT Function Clarification
How to Create an On Key Press Event in Visual Studio 2005
How to enable/disable a succeeding dropdown list if a value is selected on the first drop down list
Acces table calculated field and query filter
Strange occurance ADP/SQL2005 Subform Checkboxes autocheck when create new record
Microsoft Access 2007 Question
SQL Query - Simple Syntax Issue
Question regarding ms aCCESS FORMS
The description for Event ID ( 0 ) in Source ( .... ) cannot be found
msaccess 2003 and turning on a new menu toolbar from module code and turning off the main menu from the same place