samedi 12 août 2017

RAND() In WHERE clause in MYSQL

I've found this Blog post that shows a way to grab a random rows from a table : http://ift.tt/1G9jJi9

I used it in a heavy delete query that I was trying to LIMIT and it worked, while also being quite fast.

DELETE table1 FROM table1 
    JOIN table2 ON table2.id = table1.salesperson_id 
    JOIN table3 ON table3.id = table2.user_id
    JOIN table4 ON table3.office_id = table4.id
WHERE table1.type = "Snapshot" 
    AND table4.id = 113 OR table4.parent_id =113
    AND RAND()<=0.001;

I don't understand how does this works. I tried googling extensively, but I found nothing regarding a RAND() in the WHERE clause that's used in this way. Neither did the docs give anything about this.

Thank you in advance.

P.S. I'm Using MYSQL 5.5




Aucun commentaire:

Enregistrer un commentaire