mid((user)from(-1)) meaning in mysql. what does from(-1) mean?

what does the following query mean in mysql?

select  user  from mysql.user where user=''!=(mid((user)from(-1))='t')

do you know what’s the meaning of mid((user)from(-1)? it’s very strange for me. user is the name of one of the tables in mysql

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

As stated in the documentation, the MySQL MID() function is a synonym for the SUBSTRING() function. The SUBSTRING() function can be called in different ways (see documentation), among them in the form

SUBSTRING(str FROM pos)

This means “extract the substring from the string str, starting at the position pos“.

The documentation also states:

It is also possible to use a negative value for pos. In this case, the beginning of the substring is pos characters from the end of the string, rather than the beginning.

So that means, mid((user)from(-1) should give you the last character of the contents of user.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x