views:

32

answers:

2

I have a table, whose fields are

id, name, link

the link holds the name of the page like "link" = "index.php". Now I want to update this field and add "page=" in front of "index.php". Using this method I would like to update every entry in my table.

My desired SQL syntax need to be something like this

UPDATE mytable set link= 'page=' + <existing value of link>;

Anyone know what to accomplish this?

+2  A: 
UPDATE mytable Set link = "page:" || link
James Anderson
this didn't worked, it changed my every link to '0'
Starx
@Starx: that is puzzling - it ought to work. The WHERE 1 condition in your question is unnecessary; it is implied by the absence of any WHERE clause. You say that the links were changed to 0? I suppose that if a DBMS did something...scrappily...then if you use '+' in place of the '||' then you might get both strings converted to numbers, which fails, leading to a dummy value of zero. However, you have to have mistyped the SET clause and the DBMS has to be buggy, so it is implausible.
Jonathan Leffler
I have removed the WHERE statement, and may be the reason for your sql not to work is the fact that I am was using mysql.
Starx
+1  A: 

If you're using MySQL you can try:

UPDATE mytable SET link = CONCAT("page:", link)
ilbesculpi