I created a table consists of two columns, id
and name
.
create table City(id integer, name varchar(100));
insert into City(id, name) values (1, "Jakarta"), (2, "Bandung"), (3, "Tangerang"), (4, "Depok"),
(5, "Surabaya"), (6, "Lampung"), (7, "Balikpapan"), (8, "Bogor");
I would like to pick a row randomly via the id
. The code select floor(rand()*8) + 1
works fine. It does give random integers from 1 to 8.
The line
select * from City where id = floor(rand()*8) + 1
should always return one row only from City
. But when I tried, it sometimes return more than one row, or even none. Why is this? thanks.