How can I order by dash?
For instance, I have these data below,
page_id url
1 - a
2 - b
3 --- c
4 --- d
5 - e
6 - f
7 -- g
8 -- h
Result that I am after,
page_id url
1 - a
2 - b
5 - e
6 - f
7 -- g
8 -- h
3 --- c
4 --- d
If I do this,
ORDER by x.url ASC
I still get this,
page_id url
1 - a
2 - b
3 --- c
4 --- d
5 - e
6 - f
7 -- g
8 -- h
Any ideas?
EDIT:
My actual SQL,
SELECT
*,
IF(grandparentURL REGEXP '^[a-z0-9\-]+$', CONCAT('--- ', url), IF(parentURL REGEXP '^[a-z0-9\-]+$', CONCAT('-- ', url), CONCAT('- ', url))) AS url
FROM
(
SELECT
p.page_id,
p.url,
p2.url AS parentURL,
p3.url AS grandparentURL
FROM page AS p
LEFT JOIN page AS p2
ON p.parent_id = p2.page_id AND p.page_id != p2.page_id
LEFT JOIN page AS p3
ON p2.parent_id = p3.page_id AND p2.page_id != p3.page_id
WHERE IF('5' REGEXP '^[0-9]+$', p.page_id != '5', p.page_id IS NOT NULL)
AND p.url != 'cms'
) x
ORDER by x.url ASC
Do MULTIPLE order by… FIRST by the position where space is found first all grouped… from that, then sort by the entire URL. Since the common – b and – a will be in the same grouping, their space keeps them in group “1”… then, from that, the entire URL will force your proper – a, – b, – c, etc