0

I m trying to get number in between "sims_7009_alaira", i want 7009.

SELECT sno,dbase, SUBSTRING_INDEX(dbase, 'sims_', -1)temp
FROM school

How should i do that in SQL

Mathieu Dumoulin
  • 12,126
  • 7
  • 43
  • 71

3 Answers3

2

Give this a try:

select substring_index(SUBSTRING_INDEX(dbase, '_', 2),'_',-1) from school;

Check this here: SQL Fiddle

Yusuf Hassan
  • 1,933
  • 1
  • 12
  • 21
0

Just use substring_index() two times:

SELECT sno, dbase, substring_index(substring_index(dbase, 'sims_', -1), '_alaira', 1) as number FROM school

phpforcoders
  • 326
  • 1
  • 9
0

Do this instead:

SELECT sno,dbase, SUBSTRING_INDEX(SUBSTRING_INDEX(dbase, "_", 2),'_',-1) temp
FROM school;

For more insight see this.

cdaiga
  • 4,861
  • 3
  • 22
  • 42