Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can I select tuples based on a specific part of string input

I am using MySQL to perform this operation. For example I want to select phone numbers that do not begin with ‘456’. What is the query to get tuples where the number does not begin with 456 and does not appear any where else.

I tried WHERE phone NOT LIKE '%456%' but that deselects all numbers with 456 in them.

List of phone numbers

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

List of phone numbers

Result I got

Result I got. This removes all numbers with 456 in them. Not just ones at the beginning

>Solution :

None of your phone numbers begin with 456, they all begin with 1-. It seems like you want to check if the second part of the number is 456, not the beginning. So use

WHERE number NOT LIKE '%-456-%'
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading