PDA

View Full Version : SQL Statement help


CelticTiger
2007-11-20, 12:34 PM
I've been trying to delete some links from my database using the following statement:

DELETE FROM `links` WHERE (SELECT * FROM `links` WHERE `url` LIKE '%domain%')

but get the following error:

"Operand should contain 1 column(s)"

Can anyone tell me where I'm going wrong?

Thanks!

HowlingWulf
2007-11-20, 04:06 PM
Why do you have SELECT in there?
Should be more like

DELETE FROM `links` WHERE `url` LIKE '%domain%';

CelticTiger
2007-11-20, 04:42 PM
Yeah - tried that and was getting an error with that one too....so figured I needed a subquery.

Useless
2007-11-20, 08:58 PM
Wouldn't the simplist solution be
delete from 'links' where 'url' = 'whatever'

CelticTiger
2007-11-20, 09:30 PM
It would if it was just one url :) unfortunately there are about 1500 from one domain that I need to delete - plus many more domains will pop up I'm sure that will need the same treatment.

shunga
2007-11-21, 07:59 AM
I would use this:

DELETE FROM links WHERE url LIKE '%domain%'

CelticTiger
2007-11-21, 11:49 AM
I tried that before posting - no luck with it - which is why I tried using the subquery.

Does Sparky still frequent the board?

CelticTiger
2007-11-21, 11:56 AM
I got it :)

shunga
2007-11-21, 12:22 PM
I tried that before posting - no luck with it - which is why I tried using the subquery.

MySQL can be quite pedantic with quotation marks.

Glad you could find the solution.