0

Apologies if this is a duplicate question but I was unable to find the correct result but that could be down to the phrasing of my question but here goes.

I have a table with BIGINT primary keys. I have a search facility which primarily will search for a primary key from a barcode with a string prefix.

So my search takes the prefix matches it to the target table, strips the prefix and searches - works great. But users can also search for secondary values like order references etc.

One such contains Amazon order references like 204-5032532-4220. The search is designed to look in the ID column first where id=reference, and if that doesn't return any results it will move on to searching a series of seconday columns with the value.

However what I am seeing is the first query:

select * from `table` where `id` = '202-955552-9066709';

Is returning row id= the first part of the reference before the first - so in this example I get row id = 202.

Am I missing something fundamental in the way MySQL works - is it treating my value as INT because the column is numeric? I can obviously change the logic of my code, detect if the barcode matches otherwise don't check the value against the id but this seems to me to be strange behaviour?

I'm using 8.0.44.

New contributor
UrbanwarfareStudios is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
2
  • 3
    This question is similar to: Function is accepting varchar when input is set to INT. If you believe it’s different, please edit the question, make it clear how it’s different and/or how the answers on that question are not helpful for your problem. Commented 2 days ago
  • What else can it do? You can detect the dash and fix it. Why not show the whole query? Commented 2 days ago

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.