I try to implement a query by using Between Clause,but there is some problem in this
first query for S_E1:
this query return exact data which i require and here data count is 43.
select RECORD_TIMESTAMP as DateRecorded, ROUND (S_E1 ,2 )as S_E1
from TBL_SENSORS
Where RECORD_TIMESTAMP Between '4/28/2012 12 :00 AM'
and '5/17/2012 12 :00 AM'
And ( S_E1 Between 10 And 100 )
Second Query for S_E2:
this query return exact data which i require and here data count is 68.
select RECORD_TIMESTAMP as DateRecorded, ROUND (S_E2 ,2 )as S_E2
from TBL_SENSORS
Where RECORD_TIMESTAMP Between '4/28/2012 12 :00 AM'
and '5/17/2012 12 :00 AM'
And ( S_E2 Between 10 And 100 )
Problem :
But when i combine these to queries in a single query then it give wrong data.It gives me 73 rows.I think it should give 111 rows
select RECORD_TIMESTAMP as DateRecorded,
ROUND (S_E2 ,2 )as S_E2,
ROUND (S_E1 ,2 ) as S_E1
from TBL_SENSORS
Where RECORD_TIMESTAMP Between '4/28/2012 12 :00 AM'
and '5/17/2012 12 :00 AM'
And ( S_E2 Between 10 And 100)
and (S_E1 Between 10 And 100 )
Please give some idea where i am wrong here..
Use
ORinstead ofANDopeartorIn the query, it is not guaranteed that you will get 111 records because there may be common records for two conditions.
condition 1 –
( S_E2 BETWEEN 10 AND 100 )condition 2 –
( S_E1 BETWEEN 10 AND 100 )Or
Use Union All in two queries to get all records (111).