79749942

Date: 2025-08-29 07:30:33
Score: 0.5
Natty:
Report link

Imagine having a big "products" table (id,name,...) with massive data, in number of columns and quantity of data (few billion rows). Now, the users want to upload a list of (existing) product IDs and mark a few hundred/thousands of these items as "discounted" and set a discount for them in specific date range, and also give them new discount names. So you would just make a new table called "discount_products" (id, name, discount, date_from, date_to) and in main query just add: LEFT JOIN discount_products dp ON (products.id=dp.id AND NOW() >= dp.date_from AND NOW() <= dp.date_to) and add new select fields, and use COALESCE(discount_products.name, products.name) to get the proper name column.

Reasons:
  • Long answer (-0.5):
  • No code block (0.5):
  • Single line (0.5):
Posted by: TomoMiha