PipBoy2000
PipBoy2000

Reputation: 440

How to change MySQL column values within selected date range

Im facing a problem with change column value within selected date range. Simply i want to disable all products (set 0 value instead of 1) within a desired date range like below:

My query is

SELECT * FROM `product` 
WHERE `date_add` > '2015-08-01 00:00:00'
AND  `date_upd` < '2016-08-01 00:00:00' 
SET `active` = 0

But PHPMyAdmin throws error

1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SET active = 0 ORDER BY product.date_upd ASC LIMIT 0, 30' at line 5

Upvotes: 0

Views: 741

Answers (2)

Hamza Zafeer
Hamza Zafeer

Reputation: 2436

Use Update Query Instead of select.

The UPDATE statement is used to update records in a table.

update `product`
set `active`='0' 
WHERE `date_add` > '2015-08-01 00:00:00'
AND  `date_upd` < '2016-08-01 00:00:00' 

Upvotes: 1

mgadrat
mgadrat

Reputation: 154

You're supposed to use an UPDATE Statement to change a value

UPDATE product
SET active = 0
WHERE date_add > '2015-08-01 00:00:00'
AND  date_upd < '2016-08-01 00:00:00'   

Here's to documentation: http://dev.mysql.com/doc/refman/5.7/en/update.html

Upvotes: 2

Related Questions