Haris
Haris

Reputation: 763

MySQL: Comparison operator not working

I'm using the following code. It is working fine but when I use the date filter it stops working. I have use the comparison operator in sql. I have searched for questions but have not found the desired answer.

        SELECT SUM(retailerData.poster), SUM(retailerData.banners), SUM(retailerData.tradeLetters), SUM(retailerData.stickers) , 
    SUM(retailerData.buntings),SUM(retailerData.dangler) FROM retailerData INNER 
    JOIN retailer ON retailer.retailerID=retailerData.retailerID WHERE
   '2016-08- 24'<= retailerData.visitDate <='2016-09-03' 
    AND retailer.retailerID IN( SELECT 
    retailer.retailerID FROM retailer INNER JOIN office ON office.officeID= 
    retailer.officeID WHERE office.officeID IN( SELECT officeID FROM office          
    WHERE 
    parentOfficeID IN( SELECT officeID FROM office WHERE parentOfficeID IN    
    (SELECT 
    officeID FROM office WHERE officeName='Faisalabad Belt') ) ))

Help me regarding this.

Upvotes: 0

Views: 83

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1271151

You have this condition:

WHERE '2016-08- 24'<= retailerData.visitDate <= '2016-09-03' 

In most dialects this is not standard -- neither the ternary operator nor the space in the date literal.

Try this:

WHERE '2016-08-24'<= retailerData.visitDate AND
      retailerData.visitDate <= '2016-09-03' 

Upvotes: 5

Related Questions