3

I have a field in database named experience and it has values like 5 Years or 2 Years etc. Now I want to search all users having experience between 2 years to 5 years. How can I do that? How can I apply a range on string like 2 years.

1
  • DB::table('experience')->whereBetween(what you want)->get(); you can try wherebetween Commented Mar 7, 2018 at 6:17

2 Answers 2

1

you can try this

  DB::table('experience')->where(function ($query) use ($YOURVARIABLE) {
        $query->where('2years', '<=', $YOURVARIABLE);
        $query->where('5years', '>=', $YOURVARIABLE);
    })->get();
Sign up to request clarification or add additional context in comments.

2 Comments

but please can you tell me how it happens that a string is dealing like integer on comparison operator?
In the above case, I just checking an where condition using where condition it check the users between 2 to 5 years experience
0

first of all take all values from data with the years, store them in a array. than remove the the static 'Years' word from the string, you will get number, than apply range query on it. select * from YOURTABLE where YEAR_RANGE 'FIRST_VALUE' and 'SECOND_VALUE' order by YEARS desc;

1 Comment

but dont you think it will make query slow?

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.