Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

337
Visualizações
CHECKING if a value exists in a table SQL

I am making a bot where I need to store the commandname and commandreply in the database. I am using mySQL Workbench.

I want to check if the commandname that the user tries to make is already in the table, and if so display that. If not, then carry on (make the command).

connection.query("SELECT commandname FROM commands WHERE EXISTS (commandname = " + args[0] + ")" 

(Where args[0] is the command name). This is what I initially thought, although I don't have much experience in SQL. I'm not sure what this would display if it exists, or if it doesn't exist.

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

SELECT count(*) FROM commands WHERE commandname = ' + args[0] + '

if it returns 0 then insert else update.

A better approach would be to update first and see how many rows are updated if it's 0 then insert, in which case it will run only 1 query most of the time (assuming update is more frequent than insert).

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda