mysql - INSERT INTO with SELECT and rand() confusing variables -


i trying make part of table copied table b:

@t1 := 1 insert b select x, y, (@t1:=@t1+1) z=1 order rand() limit 10 

what wanted in table b (third column) values 1 10, making values 12, 124, 45 etc... wonder if first variables , order rand() values never exceeds numbers of rows in table a.

is there other way 10 random rows b , mark them in third column (sort column) 1 10? in 1 mysql statement, know how 10 inserts ;-)

sort first, calculate row number on rows returned order by/limit:

set @t1 := 1;  insert b select x, y, (@t1:=@t1+1) (   select x, y     z=1   order rand()   limit 10) ten_rows 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -