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
🎥 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.