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 & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.