Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySql: How quotes around date(string) affects the results?

Tags:

sql

mysql

Difference between two queries marked with ^

SELECT COUNT(*) 
FROM customers_reports AS cr 
JOIN customers_docs on customers_docs.customerId=cr.customerId 
WHERE cr.firstDepositDate >= 2015-12-01  AND customers_docs.docs = "None";

This query returns 2 results.

SELECT COUNT(*) 
FROM customers_reports AS cr 
JOIN customers_docs on customers_docs.customerId=cr.customerId 
WHERE cr.firstDepositDate >='2015-12-01' AND customers_docs.docs = "None";  
                            ^          ^                                                                                                                                        

While this query returns 30,000 results.

May someone explain why?

like image 832
Moyshe Zuchmir Avatar asked Sep 13 '25 05:09

Moyshe Zuchmir


1 Answers

Without single quotes the date value becomes the arithmetic expression and 2015-12-01 is 2002 which is obviously affect the result

like image 139
Madhivanan Avatar answered Sep 14 '25 18:09

Madhivanan