SQL Question - Select most recent record

psycoperl

Active Member
Joined
Oct 23, 2007
Messages
339
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
  2. MacOS
  3. Web
I have two yes/no boxes (ReceivedOnATBEligible and NotATBeligible), what I need to do is modify my query which is below, to pull the most recent record with either ReceivedOnATBEligible or NotATBEligible for the specific StudentID. As there could be other records without either of the flags I can not just pull the most recent comment record.

Thanks for your assistance


Code:
 Sql_Query = "SELECT TOP 1 CommentDate, " & _
            "ReceivedOnATBEligible, NotATBeligible " & _
            "FROM tblComments " & _
            "WHERE (((StudentID)='" & StudentID & "'))" & _
            "ORDER BY CommentDate DESC;"
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Can't you just add that to the criteria?

" WHERE (StudentID='" & StudentID) & "' AND (ReceivedOnATBEligible And NotAtEligible) "

That shoud return all the records that match StudentID and also have either ReceivedOnATBEligible or NotAtEligible true.

I think that's what you want.:)
 
Upvote 0
Can't you just add that to the criteria?

" WHERE (StudentID='" & StudentID) & "' AND (ReceivedOnATBEligible And NotAtEligible) "

That shoud return all the records that match StudentID and also have either ReceivedOnATBEligible or NotAtEligible true.

I think that's what you want.:)
Thank you that is what I was leaning towards, but was not sure on how to code the condition with the YES/NO boxes.

I just made it "AND (ReceivedOnATBEligible OR NotAtbEligible) "
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,711
Members
452,939
Latest member
WCrawford

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top