Neo4j Sorting is not working with special character

Hi Friends,
I am working with neo4j and i am applying sorting on my query which is getting data from various nodes, my sorting is working fine, but I am facing one issue which is, the data which starts with special characters or the data which is null are showing first is there any possible way that I can sort with the alphabet and it should sort in alphabetical order and the data with special characters should display at last; for ex: abc,Abc, Adf, bcd, Bcd, BCD, ccd, @acv, ---003abc, ^^asd, null, null, null, null

my current result is in reverse order of the example I gave above or sometimes special characters values are showing first
Below is my Query

MATCH (actor:Actor)
OPTIONAL MATCH (actor) <-[:REPRESENT_ACTOR]- (ocdactor:OCDActor)
OPTIONAL MATCH (ocdactor) -[assign:ASSIGNED_TO]-> (ocdlocation: OCDLocation  {ocdYear: actor.currentOcdYear})
OPTIONAL MATCH (location:Location) <-[:REPRESENT_LOCATION]- (ocdlocation)
OPTIONAL MATCH (ocdlocation) -[:LOCATED_IN]-> (ocdregion:OCDRegion) -[:REPRESENT_REGION]-> (region: Region)
WITH actor, location, region
ORDER BY TOLOWER(toString(actor.firstName))  ASC 

WITH actor, location, region
RETURN  actor.firstName
skip 0 limit 25

and this is my output

You can use apoc.text.clean() in your ORDER BY Clause so that the special characters are not considered while sorting.

Hi @prnvkmr954 ,

You may not need this anymore, but if someone is reading this.


This should work as well.