# Combine UPDATE with INSERT...SELECT

**URL:** https://forum.kirupa.com/t/combine-update-with-insert-select/268668
**Category:** programming
**Created:** [August 17, 2008, 12:42am UTC](https://forum.kirupa.com/t/combine-update-with-insert-select/268668 "2008-08-17T00:42:57Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![Icy\_Penguin](https://avatars.discourse-cdn.com/v4/letter/i/f6c823/32.png) [@Icy\_Penguin](https://forum.kirupa.com/u/Icy_Penguin)
#### Post date: [August 17, 2008, 12:42am UTC](https://forum.kirupa.com/t/combine-update-with-insert-select/268668/1 "2008-08-17T00:42:57Z")

</div>

Compeltely frustrated with this but I’m looking to add some deleting (a book from a list of books that someone might be selling) functionality.

I have a list a books in a table, but when the user deletes that book, I want to essentially move the book to a different table (books\_backup) and add a couple fields at the same time (the datetime at which it was deleted, and also the book’s previous id (which was auto\_incremented) moved to a different field in books\_backup called ‘book\_id’.

This works fine:

```auto

"INSERT INTO books_backup (book_id, isbn, title, author_name_first, author_name_last, edition, course_department, course_number, course_title, img_id, price, quality, category, user) SELECT id, isbn, title, author_name_first, author_name_last, edition, course_department, course_number, course_title, img_id, price, quality, category, user FROM books WHERE id='$book_to_delete'"

```

How can I add an UPDATE statement or whatever to add the datetime to that record, since doing an ‘UPDATE WHERE id=’$id’ AND title=’$title’ AND name=’$name’’ or similar query is very inefficient?

Help much appreciated.
