I have a kind of odd problem. I am programming a controlpanel for a company internal application, that utilizes a MySQL database in the backend.
I currently have a statement like this:
SELECT * FROM users WHERE ldap_user LIKE '%--Searchterm--%' OR Firstname LIKE '%--Searchterm--%' OR Lastname LIKE '%--Searchterm--%' OR id LIKE '%--Searchterm--%';
Where "--Searchterm--" is i provide it via PHP. Now i want to be able to hand over a searchterm with leading zeroes and still be able to match it to the unpadded ids.
I know, that i could strip the zeroes with PHP, but i want a pure MySQL-solution if possible.
I have no clue what to look for, because everything i find does not address a Select-query while "searching" other fields than the id as well.
If possible i prefer a query, that does not use some wild JOINs, but plain MySQL.
Thanks @Mattt!
The solution was to use
[...] OR id LIKE TRIM(LEADING '0' FROM '--Searchterm--');
-> Facepalm
I have not though of TRIM, and did not know, you could simply use it this way.
Thanks again!