SELECT left('this is a test',7)
The output of this is here
this is
We can specify the number of characters required from left side of a string by using left function in MySQLSELECT left(name,5) FROM student
We will get left 5 chars of name field of student table.
SELECT locate('@',email) FROM `newsletter_subscribe`
This will give us a number for each record which we can use to get the userid part.
SELECT left(email,locate('@',email)) FROM `newsletter_subscribe`
This will give us Userid part but will end with one extra @ added to it. Now here is the final one we can get by subtracting 1 from the output of locate function.
SELECT left(email,locate('@',email)-1) FROM `newsletter_subscribe`
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.