Ordering cypher union output

I am not sure if this goes a bit to far to ask. Did not do any reading on the cypher querying.

This movies database contains around 28k records, so if I want to display them in a stream, I would like to receive my data ordered

MATCH (n:Actor) RETURN labels(n) as labels,n.name as name, CASE WHEN toInteger(rand()*2) = 1 THEN 'M' ELSE 'F' END as gender ORDER BY n.name
UNION 
MATCH (n:Movie) RETURN labels(n) as labels,n.title as name, '-' as gender ORDER BY n.title 
LIMIT 5

This returns first Actors, and then I guess the movies. How should I rewrite this so Actors and movies starting with A are returned first.

The sorting as written will sort each query separately and then perform the union of the results.

One constraint with a union is that the columns must be the same. It looks like you understand that.

You can use a call subquery around the union so you can process the query results further.

CALL {
  MATCH (n:Actor) 
  RETURN labels(n) as labels, n.name as name, CASE WHEN toInteger(rand()*2) = 1 THEN 'M' ELSE 'F' END as gender
 UNION 
  MATCH (n:Movie) 
  RETURN labels(n) as labels, n.title as name, '-' as gender
}
RETURN *
ORDER BY name
LIMIT 5