Angwenyi
Angwenyi

Reputation: 329

How to use 'between' in select statement

This is supposed to be an easy solution but i can't my ahead around it. I have a table enter image description here

Here is a my query

 $salary=2000;  

select deductions from nhif_tbl where to_end <=$salary and start_from >= $salary;

The query returns null. My question how do i modify the query in order to get correct deductions in this case '60'

Upvotes: 0

Views: 52

Answers (4)

sarwar026
sarwar026

Reputation: 3821

Your to_end should be 999 more than the start_from

$salary=2000;  
select deductions from nhif_tbl 
where to_end >=$salary and start_from <= $salary;

Upvotes: 0

Sa&#239;d Tahali
Sa&#239;d Tahali

Reputation: 199

that's obvious try to revers the condition!

....where to_end >=$salary and start_from <= $salary;

let's do some analyses for the conditions when it's starts the condition to_ens<=2000 it's grabs the first and the second line, and when jumps next to the second condition start_from >= 2000... well you got my point!

Upvotes: 0

Nagaraj S
Nagaraj S

Reputation: 13484

Like this

select deductions from nhif_tbl where to_end >=$salary and start_from <= $salary;

Upvotes: 0

dbugger
dbugger

Reputation: 16464

select deductions from nhif_tbl where to_end >=$salary and start_from <= $salary;

Upvotes: 1

Related Questions