Skip to main content
Known Participant
March 28, 2012
Question

filtering search results

  • March 28, 2012
  • 1 reply
  • 507 views

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.

This topic has been closed for replies.

1 reply

Participating Frequently
March 28, 2012

You are not filtering, you are truncating:

SELECT RIGHT (serial_number, 4) from MyTable

Known Participant
March 29, 2012

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.

Participating Frequently
March 29, 2012

>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.