vijay shanker
vijay shanker

Reputation: 2663

update column in all rows in mysql

I have a table called tbl_portfolio described as below and i want to modify all imagePath columns by adding projectId at start, i.e abc.jpg will change to <project_id>/abc.jpg.I am not very skilled with Mysql.. :(

| portfolioId | int(11)      | NO   | PRI | NULL    | auto_increment |
| projectId   | int(11)      | YES  |     | NULL    |                |
| customerId  | int(11)      | YES  |     | NULL    |                |
| imagePath   | varchar(500) | YES  |     | NULL    |                |
| description | text         | YES  |     | NULL    |                |
| addDate     | date         | YES  |     | NULL    |                |
| lastUpdated | date         | YES  |     | NULL    |                |
| coverPhoto  | int(1)       | YES  |     | 0       |                |

Upvotes: 4

Views: 1726

Answers (7)

Tin Tran
Tin Tran

Reputation: 6202

UPDATE tbl_portfolio
SET imagePath = CONCAT(projectId,"/",imagePath);

Upvotes: 0

Maulik patel
Maulik patel

Reputation: 2432

Please You are use Update Query.

<?php
  $Query= UPDATE tbl_portfolio SET imagePath='/abc.jpg' WHERE portfolioId=1;
  mysql_query ($Query);

?>

Upvotes: 0

Saharsh Shah
Saharsh Shah

Reputation: 29051

Try this:

Use CONCAT function to merge the string

UPDATE tbl_portfolio 
SET imagePath = CONCAT(CAST(projectId AS CHAR(20)), '/', imagePath);

Upvotes: 4

aksu
aksu

Reputation: 5235

You can include column values to another columns value. See simple example:

UPDATE tbl_portfolio SET imagePath = tbl_portfolio.projectId + '/' + tbl_portfolio.imagePath;

Upvotes: 0

arturataide
arturataide

Reputation: 374

I think this will help

UPDATE tbl_portfolio SET imagePath = CONCAT('/', projectId);

Upvotes: 0

Fr0g
Fr0g

Reputation: 252

you can use udate table command, the exact syntax will be like -

UPDATE tbl_portfolio SET imagePath='/abc.jpg';

more infoe here - http://dev.mysql.com/doc/refman/5.0/en/update.html

Upvotes: -2

naveen goyal
naveen goyal

Reputation: 4629

Try this without where clause its update all rows. read this for more http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_concat

UPDATE tablename 
set imagePath = CONCAT(CAST(projectId AS CHAR(20)),"/",imagePath)

Upvotes: 0

Related Questions