Query Question

rs197290

New member
Local time
Today, 15:28
Joined
Jun 8, 2007
Messages
5
I have 4 fields that I am doing a query on.

Date
Time
Comments
Type of Event

I am trying to query and display only the 3 most recent records based on the Type of Event. I am having a problem where I am either receiving the records from today's date or yesterday's date. We do a turnover log at the change of every shift (7am, 3pm and 11pm). I need to show the current mornings turnover (7am) and yesterday's turnover (11pm and 3pm). If you could help it would be very helpful.
 
The below SQL might be what you are looking for. The below example would work if you had 3 types of events.

SELECT TOP 3 Time, [Date], Comments, [Type of Event]
From TableName
Where [Date]= (Select Max([Date]) From TableName) and [Type of Event]=’EventName’
Union
SELECT TOP 3 Time, [Date], Comments, [Type of Event]
From TableName
Where [Date]= (Select Max([Date]) From TableName) and [Type of Event]=’EventName’
Union
SELECT TOP 3 Time, [Date], Comments, [Type of Event]
From TableName
Where [Date]= (Select Max([Date]) From TableName) and [Type of Event]=’EventName’
 
Almost there

Thank you for your reply. I have never worked with SQL before but I am figuring it out little by little. However, I am only needing to select one Type of Event but I need to query on the most recent three records by date and time and only 1 type of event. Thank you in advance for your reply.
 

Users who are viewing this thread

Back
Top Bottom