We would like to filter purchase orders either based on purchase order id (primary key) or name of the purchase order using a single search box.
We used the like parameter to search on the name field, but it doesn’t seem to work on the primary key. It works only when we use the equal operator for id(s). But it would be preferable if we can filter purchase orders using like for id(s). How to do this?
create table purchase_orders (
id int(11) primary key,
name varchar(255),
...
)
Option 1
This is horrible, performance-wise 🙂
Option 2a
Add a text column which receives a string version of
id. Maybe add some triggers to populate it automatically.Option 2b
Change the type of
idcolumn toCHARorVARCHAR(I believeCHARshould be preferred for a primary key).In both 2a. and 2b. cases, add an index (maybe a
FULLTEXTone) to this column.