SELECT RIGHT('plus2net.com',3);
Output is com
RIGHT(string, length);
Now Let us try this on our student table on name field
SELECT RIGHT(name,3) FROM student
We will get right 3 chars of name field of student table.
SELECT RIGHT('userid@example.com',(char_length('userid@example.com') - LOCATE('@','userid@example.com')))
Output is example.comSELECT LOCATE('@','userid@example.com')
Output is 7 , this is the position of @ from left side
SELECT char_length('userid@example.com')
Output is 18, this is the total length of the string
SELECT CHAR_LENGTH( 'userid@example.com' ) - LOCATE( '@', 'userid@example.com' )
Output is 11, that is the length we require to get the domain part from the email address. Now by using RIGHT function we will get the last 11 chars from the string.
SELECT RIGHT('userid@example.com',(char_length('userid@example.com') - LOCATE('@','userid@example.com')))
However we can get better solution by using SUBSTRING function, this we have used in our Project to update domain and userid part from an email address in MySQL table.
Author
🎥 Join me live on YouTubePassionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.