Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL : between value in string

I'm trying to build a query which matches the rows following these rules :

  • my rows contents ids like 'MATCH_1', 'MATCH_2', 'MATCH_4'...
  • I want to match the rows which id is between 2 boundaries: SELECT id FROM table WHERE id LIKE "MATCH_%", % must be between 2 and 5 for example. The result must be : 'MATCH_2', 'MATCH_4', 'MATCH_5'

Is it possible to do so ?

Thanks

like image 881
frinux Avatar asked Dec 11 '25 07:12

frinux


1 Answers

you mean this?

 SELECT * 
   FROM table
  WHERE row 
BETWEEN 'MATCH_2' AND 'MATCH_5';

or converted to int

  SELECT *
    FROM table
   WHERE CAST(SUBSTRING(row FROM 7) AS UNSIGNED)
 BETWEEN 2 AND 5;
like image 200
Mahmut Ali ÖZKURAN Avatar answered Dec 13 '25 22:12

Mahmut Ali ÖZKURAN