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

351
Visualizações
DELETE query for multiple records in MYSQL

I am writing an MYSQL program in C. I want to delete the records from the database for all the id_no.'s stored in the array. I know that I can delete all the records by running the query in the loop. But the issue is that there are a lot of records I want to delete( > 300). So, I wanted to know if there are any other efficient methods I can use?

unit32_t id_nos[100];
char query[256];

for(int i=0; i< 100; i++) {
   sprintf(query, "DELETE FROM Students WHERE id = '%u'", id_nos[i]);

   if(mysql_query(con, query)) {
     printf("Failed to Delete record successfully\n")
     printf("stderr: %s\n", mysql_error(con));
     mysql_close(con);
     return;
   }
else {
 printf("Record deleted successfully\n");
}
over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

You can concatenate the ids as a string and passs in the "IN" function.

over 4 years ago · Santiago Trujillo Relatório

0

If your id are obtained by a previus query you con using a delete with join in this way you dan delete all the students row matching the id retured by the subquery just with a query

    DELETE Students 
    FROM Students
    INNER JOIN (
        select id from my_prev_table 
        where my_column = 'my_value'

    ) t on t.id = Students.id
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