If this was a stored procedure I would fill a temporary table or table variable with the input selection - along with an "order column" for sorting. Then join to this table.

What is your backend DB?