So if I have results
11 The street
9 The street
59 The street
A regular ORDER BY ASC
does this
11 The street
59 The street
9 The street
How can I order by ASC
and have the numbers count up like
9 The street
11 The street
59 The street
So if I have results
11 The street
9 The street
59 The street
A regular ORDER BY ASC
does this
11 The street
59 The street
9 The street
How can I order by ASC
and have the numbers count up like
9 The street
11 The street
59 The street
Please try:
select *
From tbl
order by cast(Left(Col, PatIndex('%[^0-9]%', Col)) as int)
For MySql, please try:
select *
From tbl
order by convert(SUBSTRING_INDEX(Col, ' ', 1), UNSIGNED INTEGER)
Another solution (bit simple); just going by your sample data and assuming that all your data string have The Street
common in them. Else, what TechDo have suggested should be the One I will go for (For a generic solution)
select * from tbl
order by
cast(
(substring(col,0,charindex('The street',col))) as int)