This is kind of a weird quirk I noticed and I really just wanted to see if someone could provide insight as to why its happening.
Lets say we have a field called "account" that's a varchar(x)
These two queries will return the same result set.
SELECT * FROM table WHERE account = 1234;
SELECT * FROM table WHERE account LIKE '1234%';
I stumbled on this by accident in a script I wrote to migrate some older data and I accidentally forgot to encapsulate my string.
Can anyone tell me why this behavior happens?
update:
I feel like I may have no explained this well enough so I'm going to provide a sample table:
table_name: id - INT account - varChar(50)
entries:
ID - account
1 - "1"
2 - "12"
3 - "123"
4 - "1234"
so:
1:
SELECT * FROM table_name WHERE account LIKE '1%'
will return entries 1, 2, 3, 4
2:
SELECT * FROM table_name WHERE account = 1
will return entries 1, 2, 3, 4
3:
SELECT * FROM table_name WHERE account = '1'
will return entry 1
Why is 1 the same as 2, and why is 2 not the same as 3