0

I am having a field in a table with type varchar and their value looks similar to

  1. red-chief-men-245-brown-94581
  2. adidas-men-agora-93945
  3. kids-shoes

In this i need to get only values that ends with hypen followed by integer ex ("-94581" , "-93945") ..

Is there any way in mysql to get that

5
  • 1
    U can use dev.mysql.com/doc/refman/5.1/en/… to cut X chars from end of string Commented May 22, 2012 at 12:22
  • exactly what skowron-line say +1 Commented May 22, 2012 at 12:24
  • @skowron-line: That does not check for numbers Commented May 22, 2012 at 12:26
  • @juergen d its not number, he has varchar field after cutting it still will be string, substring_index will not cast it to number Commented May 22, 2012 at 12:27
  • @skowron-line: yes. And he wants to check for numbers at the end of his string which substring() can't. Commented May 22, 2012 at 12:29

2 Answers 2

2

Use the RLIKE operator in place of LIKE. This should work:

SELECT * FROM table WHERE foo RLIKE '.*-[[:digit:]]*$'
Sign up to request clarification or add additional context in comments.

1 Comment

This one worked for me with slight modification SELECT * FROM table WHERE foo RLIKE '.*-[[:digit:]]{3,}$'
0

Probably like this:

select  substr(searchfield,locate('_',searchfield)) as extractedfield from 
mytable where substr(searchfield,locate('_',searchfield)) > 0;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.