0

I need to run this kind of query.

INSERT INTO `book_newBookOrder` (id, volume, 5, chapterNr, sectionNr, `text`) 
SELECT id, volume, bookNr, chapterNr, sectionNr, `text`
FROM book_oldBookOrder 
WHERE booknr = 1;

The fixed value 5 in the INSERT INTO part breaks it. I must be able to specify the two values as above.

So I want to select everything with bookNr = 1 in the oldbooknr table and store that as booknr 5 in the newbookorder table.

Please advise me. Thanks.

3
  • 1
    Do it the other way around place the 5 in the select and the bookNr in the insert part. Commented May 4, 2018 at 15:02
  • are the data types matching? Commented May 4, 2018 at 15:09
  • I need to pick the bookNr I want from the one (1) and specify it as (5) for the new table. Commented May 4, 2018 at 15:14

1 Answer 1

1

You have a syntax error: The items in the first set of brackets in the INSERT should be the field names. "5" is not a field name, that's the value you want to be inserted (I assume you wish to set this value the same in every row which gets inserted?). That should be in the SELECT:

INSERT INTO `book_newBookOrder` (id, volume, bookNr, chapterNr, sectionNr, `text`) 
SELECT id, volume, 5, chapterNr, sectionNr, `text`
FROM book_oldBookOrder 
WHERE booknr = 1;
Sign up to request clarification or add additional context in comments.

2 Comments

I don't want to select 5, I want to select 1 and change it to five in the new table.
Sorry guys, I'm a bit slow today. You're right it works.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.