Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Update all fields in sql table which doesnt have a specific value

Tags:

sql

mysql

Im a novice programmer doing my own firsts project and im in need of assistance.

I have two mysql fields:

  1. Product_published = Y or N
  2. Product_day = date("z") which is the day of the year 0-365

I'd like to update all "Product_published" fields in a table in my sql database.

They are all set to "Y" and I would like to update them to "N" if the "Product_day" field contains a number which is less than the current day.

So if i have 5 products with todays day(350) and 5 with 349 I would like to unpublish the 349 ones by changing "Y" to "N" in "Product_publish".

Best Regards
Ivar Rafn

like image 644
Ivar Avatar asked Dec 31 '25 01:12

Ivar


1 Answers

Use:

UPDATE YOUR_TABLE
   SET product_published = 'N'
 WHERE product_day < 350
like image 170
OMG Ponies Avatar answered Jan 06 '26 07:01

OMG Ponies



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!