I have created fresh dataset to explain my desired result. and here is the link
Or you can trigger this command using cypher.
create
(_6 {UserName
As I said in my comment, trying to query for connected and disconnected nodes at the same time doesn't seem to be a good idea.
If you want only connected nodes, try the following query :
START me=node:node_auto_index(UserName = 'manish')
MATCH me-[:friends]-mf-[:friends]-other, me-[r?]-other
WHERE other.UserName! =~ '(?i)dh.*'
RETURN DISTINCT ID(other), r.ApprovalStatus AS status, count(mf) AS mutual, ID(me)
ORDER BY mutual DESC , status ASC
Please note that I had to add another pattern in the match clause, because your approval status is between (me) and (other), and not between (me) and (mutual friend), which is what you were doing!
This will return the first 3 lines of your expected answer and ignores dhansukh.
What about this? http://console-test.neo4j.org/?id=8lloq1
START me=node:node_auto_index(UserProfileID = '1'), other=node(*)
MATCH pMutualFriends=me-[r?:friends]-mf-[r1?:friends]-other
WHERE other.UserName! =~ '(?i)dh.*' AND other.UserProfileID? <> 1 AND r.ApprovalStatus=1
RETURN DISTINCT (other.UserProfileID?),ID(other),me.EMailID?, other.EMailID?, other.UserName?, r.ApprovalStatus, COUNT(pMutualFriends) AS mutualCount