I am writing prime number query in MySQL for number between 1 to 1000 . but my query is not working. Please suggest where is the error.
SET @primenum = 1;
SET @div = 1;
SELECT GROUP_CONCAT(primenum SEPARATOR '&')from
(select
@primenum := @primenum + 1 as primenum
from information_schema.tables t1,
information_schema.tables t2
limit 1000) as list_of_prime
where not exists( select * from
(select
@div := @div +1 as div
from information_schema.tables t3,
information_schema.tables t4
limit 1000) as list_of_div
where mod(primenum, div) = 0 and primenum <>
div);
Requires output : 1&3&5&7....&997