
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
Fetch the first letter of a column value and insert it in another column with MySQL
For this, use the concept of LEFT() function. Let us first create a table −
mysql> create table DemoTable2036 -> ( -> FirstLetter varchar(20), -> Title varchar(20) -> ); Query OK, 0 rows affected (1.01 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable2036(Title) values('Chris'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable2036(Title) values('John'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable2036(Title) values('Adam'); Query OK, 1 row affected (0.15 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable2036;
This will produce the following output −
+-------------+-------+ | FirstLetter | Title | +-------------+-------+ | NULL | Chris | | NULL | John | | NULL | Adam | +-------------+-------+ 3 rows in set (0.00 sec)
Following is the query to fetch the first letter of a column value and place it to another column −
mysql> update DemoTable2036 -> set FirstLetter=left(Title,1); Query OK, 3 rows affected (0.23 sec) Rows matched: 3 Changed: 3 Warnings: 0
Let us check the table records once again −
mysql> select *from DemoTable2036;
This will produce the following output −
+-------------+-------+ | FirstLetter | Title | +-------------+-------+ | C | Chris | | J | John | | A | Adam | +-------------+-------+ 3 rows in set (0.00 sec)
- Related Articles
- Fetch maximum ID value from the first table and insert to all the IDs in another table with MySQL INSERT INTO select?
- Fetch the maximum value from a MySQL column?
- Fetch a specific column value (name) in MySQL
- MySQL insert a value to specific row and column
- Get first date from timestamp in MySQL group by another column with duplicate value
- Pandas dataframe capitalize first letter of a column
- Capitalize first letter of a column in Pandas dataframe
- Two ways to fetch maximum value from a MySQL column with numbers
- Insert NULL value into INT column in MySQL?
- Is it impossible to add a column in MySQL specifically before another column?
- Getting maximum from a column value and set it for all other values in the same column with MySQL?
- How do I INSERT INTO from one MySQL table into another table and set the value of one column?
- Filter column value by the first character in MySQL
- Copy values of one column to another using INSERT and SELECT in a single MySQL query
- Return value from a row if it is NOT NULL, else return the other row value in another column with MySQL

Advertisements