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 |
|---|
| No Content Found. |
| Exercises & Assignments |
|---|
| No Content Found. |
| Interview Questions & Answers |
|---|
| No Content Found. |