0

I was wondering.. Is it possible, with a SQL query, to:

  • generate randomly, a list of integer number
  • insert this in a table, for a specific column, and for multiple rows

I didn't try anything, to be honest I was just asking myself the question.

EDIT: (from a comment)

Imagine that I have a table USERS, with a field named VOTES. For every users, I want to insert, in the column VOTES, a random integer number between 0 and 15. For the record, I'm working with MySQL 5.5 | MariaDB

Thanks for your answers

4
  • Provide sample data to be clear what do you want to achieve. Commented May 23, 2019 at 10:22
  • Imagine that I have a table USERS, with a field named VOTES. For every users, I want to insert, in the column VOTES, a random integer number between 0 and 15. For the record, I'm working with MySQL 5.5 | MariaDB Commented May 23, 2019 at 10:33
  • 1
    You shouldn't add question details in a comment. You should edit your question. Click on the edit link below the tags in your question. Commented May 23, 2019 at 10:35
  • @Abra you're right, sorry for missing it Commented May 23, 2019 at 11:25

1 Answer 1

2

If you want to update the column named votes in the table users with random integers between 0 and 15, you could do it in the following:

UPDATE users
    SET votes = FLOOR(RAND() * 16)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.