- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Return the first n letters of a column in MySQL
To return the first n letters, use the LEFT() function. Following is the syntax −
select left(yourColumnName,yourValue) from yourTableName;
Let us first create a table −
mysql> create table DemoTable -> ( -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> CourseTitle text -> ); Query OK, 0 rows affected (0.65 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable(CourseTitle) values('Java with Spring and Hibernate framework'); Query OK, 1 row affected (0.43 sec) mysql> insert into DemoTable(CourseTitle) values('Python Web Development'); Query OK, 1 row affected (0.22 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
Output
+----+------------------------------------------+ | Id | CourseTitle | +----+------------------------------------------+ | 1 | Java with Spring and Hibernate framework | | 2 | Python Web Development | +----+------------------------------------------+ 2 rows in set (0.00 sec)
Here is the query to return the first n letters of a column −
mysql> select LEFT(CourseTitle,20) from DemoTable;
Output
+----------------------+ | left(CourseTitle,20) | +----------------------+ | Java with Spring and | | Python Web Developme | +----------------------+ 2 rows in set (0.00 sec)
- Related Articles
- How to get first N characters from a MySQL column?
- Return only the first 15 characters from a column with string values in MySQL
- Fetch the first letter of a column value and insert it in another column with MySQL
- Retrieve records whenever a column value starts with 2 vowel letters in MySQL
- Interchanging first letters of words in a string in JavaScript
- MySQL stored procedure to return a column value?
- Filter column value by the first character in MySQL
- Styling First-Letters with CSS ::first-letter
- Set a specific value for the first three column values in MySQL?
- How to find the column mean of first n number of rows in R data frame?
- MySQL SELECT to skip first N results?
- MySQL query to display the first alphabet from strings in a separate column
- Return 0 in a new column when record is NULL in MySQL?
- Minimum number of letters needed to make a total of n in C++.
- How to return rows that have the same column values in MySQL?

Advertisements