I have a table with auto increment zerofill ID numbers. When I query the data the IDs lose their leading zeros (i.e. "000529" returns as "529"). Is there a way to preserve the leading zeros, or even generate them back in the query statement? I know I can generate them back in PHP using STRPAD, but for the specific project I am on I would like to retrieve the data as it is in the DB.
leading zeros in mysql zerofill int field not showing when queried
9.6k views Asked by Evan4623 At
3
When you select the field with leading zeros and use a UNION it will remove the leading zeros.
I found a workaround by adding:
Obviously,
id_number
represents whatever zero filled field you are trying to SELECT.