> Thus, my question is whether there’s a way for me to get "at most 5 results" in a single query?

The following _example_ **AppleScript** _code_ will do as you asked:

<!-- language: lang-applescript --> 

    tell application "Notes"
    	set the noteCount to count of notes in default account
    	if noteCount > 0 then
    		if noteCount ≥ 5 then
    			set theMatches to id of (notes 1 thru 5 in default account whose name contains "a")
    		else
    			set theMatches to id of (items 1 thru noteCount in default account whose name contains "a")
    		end if
    	end if
    end tell