3

Why its not working if my both value are same I already use with equal operator. User need to select date from & to, if the user select both same date of from & to which is 2017-08-13 it should still display all the dates of 2017-08-13 and unfortunately not working.

SELECT * FROM master_data.speed_of_service where 
( trans_time >= '2017-08-13' and 
trans_time <= '2017-08-13')

It only work if there are interval between dates

2
  • can you share the table schema? Commented Aug 15, 2017 at 0:41
  • Does the column also store the time? Commented Aug 15, 2017 at 0:41

1 Answer 1

5

If I had to guess, it is because trans_time has a time component. One easy fix is to extract the date:

SELECT ss.*
FROM master_data.speed_of_service ss
WHERE date(trans_time) >= '2017-08-13' and date(trans_time) <= '2017-08-13';

A better solution would be to add one day to the "to" date:

SELECT ss.*
FROM master_data.speed_of_service ss
WHERE trans_time >= '2017-08-13' AND
      trans_time < '2017-08-13' + interval 1 day;

This is better because it still allows the use of an index.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.