Fixed #12807 -- EmptyResultSet ORed condition

The EmptyResultSet wasn't treated correctly so the end results was
incorrect, too. The bug had been already fixed in master so only tests
added.