MYSQL insert random from list

后端 未结 2 1080
终归单人心
终归单人心 2020-12-01 07:36

I would like to add a random value to a table. While I know how to add random integers within a range, I am currently stumped on how to add a randomly selected item from a l

2条回答
  •  生来不讨喜
    2020-12-01 08:27

    If you're willing to add the services to another table...

    INSERT INTO `im` ( `im` , `service` )
    SELECT LOWER( `last` ) , (
       SELECT `service`
       FROM `service`
       ORDER BY RAND( )
       LIMIT 1
    )
    FROM `contact`
    

提交回复
热议问题