-2

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

3N1GM4
  • 3,372
  • 3
  • 19
  • 40
  • 1
    What kind of SQL you use? – Justinas Aug 21 '23 at 05:44
  • 2
    Welcome to Stack Overflow. Please read [the help pages](http://stackoverflow.com/help), take the SO [tour], and read [ask]. Also please read [how to write the "perfect" question](https://codeblog.jonskeet.uk/2010/08/29/writing-the-perfect-question/), especially its [checklist](https://codeblog.jonskeet.uk/2012/11/24/stack-overflow-question-checklist/). Then [edit] your question to improve it. – Some programmer dude Aug 21 '23 at 05:50
  • Relevant: [When to use stored procedures](https://stackoverflow.com/a/6369030/256196). – Bohemian Aug 21 '23 at 06:12
  • @Justinas Mysql – Suchi Vats Aug 21 '23 at 06:18
  • Anyhow, it got resolved, i was using div as a variable name and it is a math function in MySql. so i changed div as divi. But i struggling in understanding the twice use of tables in both the queries (main and subquery). It would be great if you can clear this to me. – Suchi Vats Aug 21 '23 at 06:20

0 Answers0