I'm trying to achieve natural/alphanumeric sorting in MySQL and having no luck. I have read several Stack articles and various articles on the topic I found in google searches. Here is the basic query I began with:
select VideoTitle, VideoID
from Filters
where VideoSource = 'Netflix'
and IMDBSeries = 'tt0367279'
and PublishDate is not null
ORDER BY VideoTitle
That query yields this result set:
Arrested Development Season 1: Ep. 1 Pilot Arrested Development Season 1: Ep. 10 Pier Pressure Arrested Development Season 1: Ep. 2 Top Banana Arrested Development Season 1: Ep. 3 Bringing Up Buster Arrested Development Season 1: Ep. 4 Key Decisions Arrested Development Season 1: Ep. 5 Charity Drive Arrested Development Season 1: Ep. 6 Visiting Ours Arrested Development Season 1: Ep. 7 In God We Trust Arrested Development Season 1: Ep. 8 My Mother, the Car Arrested Development Season 1: Ep. 9 Storming the Castle
Notice this row is out of order from a natural sorting perspective:
Arrested Development Season 1: Ep. 10 Pier Pressure
Based on the posts/articles I read, I have also tried these approaches, with their accompanying result sets:
select VideoTitle
from Filters
where VideoSource = 'Netflix'
and IMDBSeries = 'tt0367279'
and PublishDate is not null
ORDER BY CAST(VideoTitle AS UNSIGNED), VideoTitle
Arrested Development Season 1: Ep. 1 Pilot Arrested Development Season 1: Ep. 10 Pier Pressure Arrested Development Season 1: Ep. 2 Top Banana Arrested Development Season 1: Ep. 3 Bringing Up Buster Arrested Development Season 1: Ep. 4 Key Decisions Arrested Development Season 1: Ep. 5 Charity Drive Arrested Development Season 1: Ep. 6 Visiting Ours Arrested Development Season 1: Ep. 7 In God We Trust Arrested Development Season 1: Ep. 8 My Mother, the Car Arrested Development Season 1: Ep. 9 Storming the Castle
select VideoTitle
from Filters
where VideoSource = 'Netflix'
and IMDBSeries = 'tt0367279'
and PublishDate is not null
ORDER BY LENGTH(VideoTitle), VideoTitle
Arrested Development Season 1: Ep. 1 Pilot Arrested Development Season 1: Ep. 2 Top Banana Arrested Development Season 1: Ep. 4 Key Decisions Arrested Development Season 1: Ep. 5 Charity Drive Arrested Development Season 1: Ep. 6 Visiting Ours Arrested Development Season 1: Ep. 10 Pier Pressure Arrested Development Season 1: Ep. 7 In God We Trust Arrested Development Season 1: Ep. 3 Bringing Up Buster Arrested Development Season 1: Ep. 8 My Mother, the Car Arrested Development Season 1: Ep. 9 Storming the Castle
select VideoTitle
from Filters
where VideoSource = 'Netflix'
and IMDBSeries = 'tt0367279'
and PublishDate is not null
ORDER BY VideoTitle + 0 ASC
Arrested Development Season 1: Ep. 1 Pilot Arrested Development Season 1: Ep. 9 Storming the Castle Arrested Development Season 1: Ep. 8 My Mother, the Car Arrested Development Season 1: Ep. 7 In God We Trust Arrested Development Season 1: Ep. 6 Visiting Ours Arrested Development Season 1: Ep. 5 Charity Drive Arrested Development Season 1: Ep. 4 Key Decisions Arrested Development Season 1: Ep. 3 Bringing Up Buster Arrested Development Season 1: Ep. 2 Top Banana Arrested Development Season 1: Ep. 10 Pier Pressure
Any ideas?
The best solution would be to store the show title, the season, the episode number, and the episode title in separate columns.
In this case, you might be able to do some string manipulation to get what you need.
This is such a fragile solution, though.