Jump to content

[SOLVED] Mysql to match only exact digits


Prodigal Son

Recommended Posts

Leading zeros on numbers have zero significance. To do what you want would require treating the value in the sid column as a string. You would either need to cast the sid column as a CHAR type in the query or you would need to make the sid column one of the string data types.

 

What is the definition of the sid column now and why do you want or need to use leading zeros in an identifier?

Link to comment
Share on other sites

Leading zeros on numbers have zero significance. To do what you want would require treating the value in the sid column as a string. You would either need to cast the sid column as a CHAR type in the query or you would need to make the sid column one of the string data types.

 

What is the definition of the sid column now and why do you want or need to use leading zeros in an identifier?

I actually don't want to use leading zeros. I just only want to match exact digits incase search engines treat it as duplicate content. So a url such as index.php?page=something&sid=020 would also have the same content as index.php?page=something&sid=20. Not sure if search engines will count that as duplicate content. So any leading zeros on the id should go to a 404 page instead of having the same content.

 

Did you mean something like this: SELECT * FROM table WHERE CAST(sid AS CHAR) = 0020

 

I tried that but it still returned the row with id 20.

Link to comment
Share on other sites

so I wonder if it's necessary.

No. Unless you produce a link on a page with something other than the actual value, a search engine is not even going to know or try anything else. Using the CAST() function will slow down every query with it in it and making the column a character type would only be needed if you intended to have separate values like 20, 020, and 0020 that were for separate rows.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.