SELECT SUBSTRING('plus2net.com',4); // Output is s2net.com
Last 4 chars ( from right end)
SELECT SUBSTRING('plus2net.com',-4); // Output is is .com
SELECT SUBSTRING('plus2net.com',3,5); // Oputput us2ne
Starting from end, from 6th position 2 ( length) chars to be collected
select SUBSTRING('plus2net.com',-6,2); // Output is et
SELECT SUBSTRING('plus2net.com' FROM 3) // Ouptut is us2net.com
From right ( end ) starting from 7 position return 3 chars (length)
SELECT SUBSTRING('plus2net.com' FROM -7 FOR 3) // Output is net
select substring('plus2net.com',1,char_length('plus2net.com')-1)
Use this code in our student table.
SELECT id,SUBSTRING(class,1,char_length(class)-1) as class FROM student
using concat()
SELECT CONCAT(SUBSTRING('Hello, world!', 1, 5), SUBSTRING('Hello, world!', -6)); -- Output: 'Helloworld!'
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.