Skip to content

Instantly share code, notes, and snippets.

@srayhan
Created April 15, 2014 19:11
Show Gist options
  • Save srayhan/10760944 to your computer and use it in GitHub Desktop.
Save srayhan/10760944 to your computer and use it in GitHub Desktop.
Update Random Rows in a Table based on a Join Condition (PostgreSQL)
UPDATE table1 SET table1.col1 = 'some value' WHERE id IN (SELECT table1.id FROM table1, table2 WHERE table1.table2_id = table2.id and table2.colm2 = <some value> ORDER BY RANDOM() LIMIT 20
@srayhan
Copy link
Author

srayhan commented Apr 15, 2014

For mysql change RANDOM() to RAND().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment