prime numbers from 0 to 10 in mysql

1

Good afternoon, I'm having difficulty with this MySQL question:

Show the animals' names and breed code. Just show the animals that contain a prime number from 0 to 10.

I tried the following code:

SELECT nome, raca from animais where 
(codigo > 0 and codigo < 10)
and (codigo % 1 = 0 and codigo % 2 = 0) or (codigo % 1 = 0 and codigo % 3 = 0) or 
(codigo % 1 = 0 and codigo % 5 = 0) or (codigo % 1 = 0 and codigo % 7 = 0)

Give the following error only:

Error = {Error Response}

Well I'm solving questions from sqlweb.com.br. Here is the image of the site with the question, the answer and the error:

    
asked by anonymous 07.08.2018 / 19:43

1 answer

-1

As prime numbers between 0 and 10 are few and it is a rule of mathematics, that is, something accurate, we can use the fixed code to check if the number is prime:

Prime numbers between 0 and 10: 2, 3, 5, 7

SELECT nome, raca 
  FROM animais 
 WHERE codigo in (2, 3, 5, 7) 
    
07.08.2018 / 20:08