Jump to content
Fórum Script Brasil
  • 0

Como retornar uma linha do banco de dados onde apareça um dos números na primeira coluna e um dos números na segunda coluna?


thiagoprogramador
 Share

Question

Eu tenho uma sequência de números: 1, 3, 5, 7, 9, 21, 23, 25, 27, 29, 41, 43, 45, 47, 49. E quero retornar linhas do do banco de dados onde estes números aparecem na primeira e na segunda coluna.

Tentei a seguinte query: SELECT * FROM tabela_calculos WHERE NUM1 = 1 OR NUM1 = 3 OR NUM1 = 5 OR NUM1 = 7 OR NUM1 = 9 OR NUM1 = 21 OR NUM1 = 23 OR NUM1 = 25 OR NUM1 = 27 OR NUM1 = 29 OR NUM1 = 41 OR NUM1 = 43 OR NUM1 = 45 OR NUM1 = 47 OR NUM1 = 49 AND NUM2 = 1 OR NUM2 = 3 OR NUM2 = 5 OR NUM2 = 7 OR NUM2 = 9 OR NUM2 = 21 OR NUM2 = 23 OR NUM2 = 25 OR NUM2 = 27 OR NUM2 = 29 OR NUM2 = 41 OR NUM2 = 43 OR NUM2 = 45 OR NUM2 = 47 OR NUM2 = 49.

Eu preciso retornar a linha do banco de dados onde tenha o numero 1 na primeira coluna e o número 3 na segunda coluna. 

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

  • 0
20 horas atrás, lowys disse:

Olá!
Já tentou assim:
... where col1 = 1 && col2 = 3
?

Sim, mas não de certo. 

 

A forma correta é esta:

SELECT * FROM tabela_calculos
WHERE
NUM1 IN (1, 3, 5, 7, 9, 21, 23, 25, 27, 29, 41, 43, 45, 47, 49)
AND
NUM2 IN (1, 3, 5, 7, 9, 21, 23, 25, 27, 29, 41, 43, 45, 47, 49);

Link to comment
Share on other sites

  • 0
On 10/6/2021 at 1:08 AM, thiagoprogramador said:

Yes, but not sure. 

 

The correct way is this:

SELECT * FROM calculation_table
WHERE
NUM1 IN (1, 3, 5, 7, 9, 21, 23, 25, 27, 29, 41, 43, 45, 47, 49)
AND
NUM2 IN (1, 3, 5, 7, 9, 21, 23, 25, 27, 29, 41, 43, 45, 47, 49);

Thanks for sharing this. I was confused at first now I know what to do!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share



  • Forum Statistics

    • Total Topics
      149.9k
    • Total Posts
      646.8k
×
×
  • Create New...