MySQL Type Casting

Example usage - if a field is a varchar and you need to sort by a number. It will sort it alpabetically, instead of numerically. Type casting will convert it to an altenative data type.

  1. SELECT * FROM table WHERE column = 'variable' ORDER BY CAST(id AS UNSIGNED INTEGER ) ASC

Enjoy this article?

Get my best content on Javascript, CSS, PHP & Git before anyone else and special bonuses.

Get started

Add new comment