I have table grocery_items with column plu_items which has 12 digit upc code, for ex 123456789123.
How to to remove the last check digit i:e "3" in above ex. in a sql query?
I have table grocery_items with column plu_items which has 12 digit upc code, for ex 123456789123.
How to to remove the last check digit i:e "3" in above ex. in a sql query?
Just use left()
:
select left(plu_items, length(plu_items) - 1)
from grocery_items;
You should review MySQL string functions. They are well-documented.
If you actually want to remove the last digit from the data, use update
:
update grocery_items
set plu_items = left(plu_items, length(plu_items) - 1);
Be careful, because this affects all the data.
You can just divide by 10
select cast(plu_items / 10 as unsigned) as plu_items
from grocery_items