Copy link to clipboard
Copied
I am working with php/Mysql and have a table that contains many orders and each order has a long serial number. We often only use the last 4 digits of the serial number when referring to an order. I want to know how to filter my query only by the last 4 digits of the serial number so the orders are easier to reference in our system. Any ideas of how to do this are appreciated. Thanks so much.
Copy link to clipboard
Copied
You are not filtering, you are truncating:
SELECT RIGHT (serial_number, 4) from MyTable
Copy link to clipboard
Copied
Thanks a lot. Works great. I also used SELECT MID() and that worked as well. Is it possible to use one of these functions to not only select the last 4 digits as well as a single digit earlier in the serial number? Thanks a lot for your help.
Copy link to clipboard
Copied
>Is it possible to use one of these functions to not only select
>the last 4 digits as well as a single digit earlier in the serial number?
No, but you just need to use the function (or two different functions) twice in your SQL SELECT.