Refresh all fields in sql table that does not have a specific value

I am a beginner programmer who is doing his first project and they need help.

I have two mysql fields:

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

I want 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 that is less than the current day.

So, if I have 5 products with today (350) and 5 with 349, I would like to unpublish 349 by changing " Y " to " N " in the Product_publish section . "

Best regards - Ivar Rafn

+3
source share
2 answers

Using:

UPDATE YOUR_TABLE
   SET product_published = 'N'
 WHERE product_day < 350
+4
source

This SQL query should fulfill your wish.

 UPDATE your_table
 SET Product_published = 'N'
 WHERE Product_day < 350
+2
source

Source: https://habr.com/ru/post/1780798/


All Articles