4

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?

1
  • I need to have number of rows with this condition. Commented Jul 24, 2015 at 8:59

1 Answer 1

1

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;
Sign up to request clarification or add additional context in comments.

2 Comments

Add a silent conversion of string to integer as SUBSTRING_INDEX(yourcolumn,'|',1)+0
Is it not good idea to have multiple values in the same column? I need to save goals minutes, authors, tima for each game.

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.