MySQL Forums
Forum List  »  PHP

Re: How to add some char. to a varchar use update query?
Posted by: Jonathan Stephens
Date: June 23, 2005 08:26PM

If you want to update the value of the email column for every record in the table, then no WHERE clause is necessary:

UPDATE mytable SET email = CONCAT(email, '-');

However, I wouldn't do this, as (1) it's wasteful of space, and (2) if you later need to work with just the email addresses, then you'll have to strip off the dash character again. My choice would be to add the dash as part of a SELECT query. For example, if you want to get the table data in the form

email - firstname lastname

then use the query

SELECT CONCAT(email, ' - ', firstname, ' ', lastname) AS userinfo FROM mytable;

It's inefficient to store repetitive data, and there's almost always a better alternative to doing so.

Jon Stephens
MySQL Documentation Team @ Oracle

MySQL Dev Zone
MySQL Server Documentation
Oracle

Options: ReplyQuote


Subject
Written By
Posted
Re: How to add some char. to a varchar use update query?
June 23, 2005 08:26PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.