Concatenate Random Result with Where Condition Concatenate Random Result with Where Condition sqlite sqlite

Concatenate Random Result with Where Condition


The 2nd query to get 50 random rows without the row of id=100 should be:

select *from (select * from table1 where id <> 100  order by random() limit 50) 

So use UNION ALL and conditional sorting:

select *from (  select * from table1 where id = 100  union all  select *  from (select * from table1 where id <> 100  order by random() limit 50) )order by id = 100 desc