THE DOCTOR
THE DOCTOR

Reputation: 4555

Add +1 In Front of Each Selected Row of Database

I have a MySQL table containing 10 digit numbers. I need to add +1 in front of each via an UPDATE.

Let's say my SELECT statement looks like this:

SELECT *
FROM num_data
WHERE number REGEXP '^[0-9]{10}$'

How do I add +1 in front of each result of my query above?

Upvotes: 0

Views: 285

Answers (1)

Barmar
Barmar

Reputation: 781300

Use CONCAT to concatenate strings in MySQL.

UPDATE num_data
SET number = CONCAT('+1', number)
WHERE number REGEXP '^[0-9]{10}$'

Upvotes: 1

Related Questions