Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

update all rows with adding text before it

Tags:

sql

mysql

Below is how my table is

create table tab (id INT, fullname varchar(100));

Data is

insert into tab values
(1,'Full Name 1'),
(2,'Full Name 2'),
(3,'Full Name 3'),
(4,'Full Name 4'),
(5,'Full Name 5'),
(6,'Full Name 6');

I want to update the table with fullname as My Full Name is + actuallfullname. e.g. data for id 1 should be My Full Name is Full Name 1.

Any idea how to get this done in one query?

Using below query, it would be executing n times as I have so many records.

UPDATE tab SET fullname='My Full Name is Full Name 1';

sqlfiddle

like image 230
Fahim Parkar Avatar asked Sep 13 '25 20:09

Fahim Parkar


1 Answers

Use CONCAT.

UPDATE tab 
SET fullname = CONCAT('My Full Name is ', fullname)

SQLFiddle Demo

like image 191
John Woo Avatar answered Sep 15 '25 11:09

John Woo