What does sql query actually compare when we use comparator with string data type ?
select * from users where name>='abcd';
>=
compares two strings based on the collation defined for the string.
In general, this means that they are compared alphabetically. So your query would return anything that would follow 'abcd'
in the dictionary (plus 'abcd'
), including 'abcde'
and 'zzz'
.
You don't specify the database you are using. Whatever it is, it certainly has documentation on collations and character sets.
Strings have a natural, lexicographical order. This query will select all the names that come "after" abcd
, such as bob
(since b
is after a
) or allen
(since l
is after b
).
>
and <
and =
means that they are compared alphabetically when that happens, a BOOLEAN
value is returned (i.e., a TRUE
, FALSE
, or NULL
).
In your example, the SQL code would return results that were "greater than" or after acbd
, so thinks like bbbb
or z
presumably.