Reputation: 4834
I have a field in my (MySQL
) Database that has invoice numbers in this format: 024/14
The 024
part is an automatic increment handled from the code, not from the database, and the 14
is actually the Year.
Is there a way to sort by this field, having in mind that the year's number comes last, without having to restructure the table?
Upvotes: 0
Views: 36
Reputation: 903
Try this:
select inv_number from yourtable order by substring(inv_number, 5, 2), substring(inv_number, 1, 3)
Upvotes: 1
Reputation: 686
Try this select:
select * from table_name order by SUBSTRING_INDEX(field_name, '/', 1);
where field_name - your field with invoices numbers.
Upvotes: 0