dimanche 20 décembre 2020

Problem when trying to update the result of a specific select

I have the following query to aleatory select up discounted product registrations. This works perfectly.

SELECT * FROM products AS r1 
JOIN (SELECT CEIL(RAND() * (SELECT MAX(id) FROM products)) AS id) AS r2 
WHERE r1.id >= r2.id 
AND discount_rate <> 0 
ORDER BY r1.id ASC LIMIT 15

Okay, but how do I fill these records with information. I am trying to indicate that they are able to appear in a special offers section. From the query that works, I wrote the following update query that doesn't work:

UPDATE products 
SET is_special_offer=1 
WHERE IN (SELECT * FROM products AS r1 
  JOIN (SELECT CEIL(RAND() * (SELECT MAX(id) FROM products)) AS id) AS r2 
  WHERE r1.id >= r2.id 
  AND discount_rate <> 0 
  ORDER BY r1.id ASC LIMIT 15) 

Error "Operand should contain 1 column(s)"

I don't know how to update these results. Can someone help me?




Aucun commentaire:

Enregistrer un commentaire