Query Question.

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
$var
Forum Contributor
Posts: 317
Joined: Thu Aug 18, 2005 8:30 pm
Location: Toronto

Query Question.

Post by $var »

What would the SQL statement be to delete part of a string from an entry.
i want to change imi/picture.jpg to picture.jpg in over 250 entries.

I tried winging it with this:
DELETE 'imi/' IF EXISTS 'Pictures'

but obviously it is incorrect.

can anyone help?
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

DELETE is to delete a row. You need an UPDATE.

If it's always the same string you're removing then try:

Code: Select all

update tablename set fieldname = substr(fieldname,4) where substr(fieldname,1,4) = 'imi/';
EDIT | Make sure you have a backup first!
User avatar
$var
Forum Contributor
Posts: 317
Joined: Thu Aug 18, 2005 8:30 pm
Location: Toronto

Post by $var »

thanks!
User avatar
$var
Forum Contributor
Posts: 317
Joined: Thu Aug 18, 2005 8:30 pm
Location: Toronto

Post by $var »

note: when i actually did this with this command, i still ended up with /img_photo.jpg, not img_photo.jpg
in fact, when i rewrote it as:

Code: Select all

update tablename set fieldname = substr(fieldname,1) where substr(fieldname,1,1) = '/';
it still didn't remove the slash. does this command not remove slashes?
Post Reply