Generate proper SQL when table-prefixed hash key is used in order