I’m just wondering why
CREATE TABLE employeeinfo(
position CHAR(50),
salary INT NOT NULL,
branch CHAR(50)
) ENGINE=InnoDB;
SELECT * FROM EMPLOYEEINFO
WHERE position >= 'Regional Manager';
is returning every person in the table.
Is it because it’s some kind of array? It’s not an alphabetical thing. Could it be because of the values in memory being greater than Regional Manager’s value in memory? I think someone told me it was because of a difference between pointer locations in memory?
There’s no such thing as an array in relational databases.
If the statement is returning every entry, it’s because the condition always evaluates to true. This implies that
positionis always >= the string ‘Regional Manager’, so the task is to determine why this is the case.If
positionhas a text type, then the comparison is a string comparison, so something such as ‘S’ would be >= ‘Regional Manager’. String comparisons depend on the encoding (called “character set” in MySQL parlance) and collation used for the column. The collation determines the order for individual characters. Additionally, MySQL uses case insensitive comparisons by default for most collations, so'a' < 'Regional Manager'but's' >= 'Regional Manager'.If
positionholds a numeric value, then MySQL will convert ‘Regional Manager’ to a number using as much as the beginning of the string as can be interpreted as a number:If this is the case, then as long as
positionis positive, it will be >= ‘Regional Manager’.