Fix error with a query returning an empty result set: row number 0 is out of range 0..-1