Hayk Makyan
Hayk Makyan

Reputation: 47

mysql query with explode

I have a table with this type of value 20|10|5|8|19| (with separator)

I need to select rows, where first value (for example after explode), less than 20.

$arr = explode("|", "goal_times");
$first_goal_time = $arr[0];

But how to do this in Mysql query?

Upvotes: 4

Views: 1930

Answers (1)

vhu
vhu

Reputation: 12788

In general you shouldn't have multiple values with separator in the same column. In this case you can get away with SUBSTRING_INDEX()

SELECT * 
 FROM yourtable 
 WHERE 
  SUBSTRING_INDEX(yourcolumn,'|',1) < 20;

Upvotes: 1

Related Questions