0

Query

$dateCond = " AND TIMESTAMP BETWEEN $startTime AND $endTime";

SELECT TITLE, PID, TYPE
  FROM REPORT_LIST_VIEW
 WHERE $dateCond
 GROUP BY TITLE, PID, TYPE 
 ORDER BY TITLE DESC`

This query works fine if start and end date are different. It fails when both are same. Is there any wrong in my query.

Or do i need to try

$dateCond = " AND TIMESTAMP >= $startTime AND TIMESTAMP <= $endTime";

MarioAna
  • 815
  • 7
  • 11
drup
  • 1,047
  • 2
  • 9
  • 17
  • When you say "fail" do you mean it gives an error or just returns nothing? If it's an error please post the error. – MarioAna Aug 13 '15 at 05:41
  • Its display 'No result found'. But it as result – drup Aug 13 '15 at 05:44
  • Can you post the values of $startime and $endtime please. – MarioAna Aug 13 '15 at 05:51
  • According to [other users observation](http://programmers.stackexchange.com/questions/160191/why-is-sqls-between-inclusive-rather-than-half-open) the SQL standard dictates the BETWEEN operator to be inclusive. What you see here is apparently a bug in your DBMS. What database is it? – cha Aug 13 '15 at 05:51
  • Why GROUP BY when no aggregate functions are involved? Do SELECT DISTINCT instead if that's what you want! – jarlh Aug 13 '15 at 07:34

2 Answers2

0

Between include the edges Lets say your start and end date are 30/12/2015 00:00:00 so only on this specific second (or even by same millisecond) you will get the result

Or do i need to try

$dateCond = " AND TIMESTAMP >= $startTime AND TIMESTAMP <= $endTime";

This will give you the same results as using between

For more information: Related question

Community
  • 1
  • 1
Roy Shmuli
  • 4,979
  • 1
  • 24
  • 38
0

remove AND from this declaration $datecond=" AND TIMESTAMP BETWEEN $startTime AND $endTime"; unless it result in sql error as the query became where AND ... this is wrong syntax, or else you can us 1=1 $dateCond = " AND TIMESTAMP BETWEEN $startTime AND $endTime";.

R.Rajesh
  • 1
  • 4