Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8727083
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:22:27+00:00 2026-06-13T08:22:27+00:00

I have to delete records that contain the id in an array. I just

  • 0

I have to delete records that contain the id in an array.

I just don’t know which is better to use. Which is faster and more efficient?

code 1

$array = array('123','456','789' ...)//over 900 entries
$id = implode(',', $array);
$sql = 'DELETE FROM email WHERE id IN ('.$id.')';
//execute sql

or

code2

$array = array('123','456','789' ...)//over 900 entries
for($x=0;$x<count($array);$x++){
  $sql='DELETE FROM email WHERE id = '.$array[$x].' ';
  //execute sql
}

Which from the two is faster and more efficient when executed?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T08:22:28+00:00Added an answer on June 13, 2026 at 8:22 am

    Case 1 will be faster.

    It is not only executing time of the query that determines the total amount of time. Parsing, preparing and planning also take time. In case 2 that needs to be done several times, in case 1 only once. Deleting a row will be equally fast, but it is the query overhead that makes case 1 faster.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to delete multiple records at once. I have two tables, one that
I have a mysql table that I need to only contain 20 newest records
I have an asp.net webpage that contain a gridview with edit, select and delete
Delete the records that have the minimum of records, I have 2 tables person
I have been having an issue with the $this->delete() method that deletes a record
I have button, which fires an event, that deletes a record from the database.
I have written this code inside a servlet to delete certain records from three
I have a table with about 100k records and I want to delete some
I have column where i save timestamp of records and I wants to delete
I have a simple program that lets you add, edit, list, search and delete

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.