Reputation: 925
I have a query which has typographical error:
SELECT
SUM(qty)
AS
'aqty1'
FROM
po_details
WHERE
product_id ='1196'
AND
so_number = '1m';
It should be:
SELECT
SUM(qty)
AS
'aqty1'
FROM
po_details
WHERE
product_id ='1196'
AND
so_number = '1';
But the first wrong query which have so_number = '1m'
mysteriously outputs correctly, the same output as the second correct query does, which should not be the case, right?
product_id
and so_number
's data types are both INT
. so_number = '1m'
should've worked if so_number
's data type is VARCHAR
, since I've enclosed the 1m
inside quotes, and the condition set was so_number LIKE '%1m%'
.
So why is the above typo query works? Shouldn't MySQL error and says that it can't find the 1m
and consider it as 1
? Is this a known bug? I am using MySQL 5.6.14.
Here's a screenshot:
Upvotes: 0
Views: 223
Reputation: 30849
It's implicit conversion, performed by MySQL. You can read about that here:
When an operator is used with operands of different types, type conversion occurs to make the operands compatible. Some conversions occur implicitly.
e.g.:
mysql> SELECT 1+'1';
-> 2
mysql> SELECT CONCAT(2,' test');
-> '2 test'
Upvotes: 3