Write a query to retrieve the first four characters of name from the student table

The examples use the students table from our MySQL tutorial: id, name, city, marks, course_id.

SELECT name, LEFT(name, 4) AS first_four
FROM students;
Tutorials Class - Output Window
name first_four
Robin Robi
Maria Mari
John John
Asha Asha
Vikram Vikr
Neha Neha

SUBSTRING(name, 1, 4) gives the same result. Names shorter than four letters are returned as they are. See MySQL String Functions.


Learn more about the similar topics:
Tutorials
MySQL String Functions
MySQL Date Functions
Exercises & Assignments
Write a query to fetch the names of the students in upper case
Write a query to retrieve the first four characters of the name
Interview Questions & Answers
Write a query to retrieve the first four characters of name from the student table
How to get the current date and time in MySQL?