jontly
jontly

Reputation: 238

Really basic mySQL Query - replace values

This must be really simple:

On mySQL -

UPDATE exp_channel_data

Where entry_id is between 10169 and 10860

If custom_field is value 18

REPLACE with 17

Any ideas? I'm really struggling with the little knowledge I have!

Upvotes: 2

Views: 292

Answers (2)

JClaspill
JClaspill

Reputation: 1745

UPDATE exp_channel_data 
SET custom_field = 17 
WHERE custom_field = 18 AND entry_id > 10169 AND entry_id < 10860

If you want to include 10169 and 10860 use a BETWEEN statement.

The BETWEEN operator functions as 'greater than or equal to' [NUMBER] AND 'less than or equal to' [NUMBER].

BETWEEN example:

UPDATE exp_channel_data 
SET custom_field = 17 
WHERE custom_field = 18 AND entry_id BETWEEN 10169 AND 10860

Upvotes: 0

Andrew
Andrew

Reputation: 14447

UPDATE exp_channel_data
SET    custom_field = 17
WHERE  custom_field = 18
AND    entry_id BETWEEN 10169 AND 10860

I actually don't remember for sure whether BETWEEN is supported; if not:

UPDATE exp_channel_data
SET    custom_field = 17
WHERE  custom_field = 18
AND    entry_id >= 10169
AND    entry_id <= 10860

Upvotes: 2

Related Questions