1

I'm trying to make the following transaction work, but the I get a mysql error near SELECT. I've double-checked that all column names are correct.

Error message

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'INSERT INTO articles (catid,content,title,keywords,isactive) (SELEC' at line 2

SQL

START TRANSACTION; 
INSERT INTO articles (catid,content,title,keywords,isactive) 
(SELECT 1, pendingarticles.content, pendingarticles.title, 
pendingarticles.keywords, 1 
FROM pendingarticles 
WHERE pendingarticles.id=1);
DELETE FROM pendingarticles WHERE id=1; 
COMMIT;

UPDATE

The code itself works. Both the INSERT INTO - SELECT part, and the DELETE part. Something's wrong with the transaction. Perhaps ;? Or my db server can't do transactions?

15
  • 1
    What does the error say ? Commented Jul 18, 2013 at 14:05
  • You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'INSERT INTO articles (catid,content,title,keywords,isactive) (SELEC' at line 2 Commented Jul 18, 2013 at 14:06
  • 1
    Did you forget VALUES, INSERT INTO table (....) VALUES (...); ? Commented Jul 18, 2013 at 14:07
  • 2
    Did you try to run only the select statement? does it work? Commented Jul 18, 2013 at 14:13
  • 2
    My lolcat says: "MyIZAM can't into tranzactionz" Commented Jul 18, 2013 at 15:17

3 Answers 3

2

MyISAM Engine does not support transactions. MyIsam engine transaction support

To support transactions you have to change the engine f.e. to InnoDB. Setting the Storage Engine

Sign up to request clarification or add additional context in comments.

2 Comments

And here's the winner for me! somebody that can see past his nose before answering :D
It turns out that the server does not support innoDB, so I must continue working without this feature. Thanks for helping.
0

you want:

INSERT INTO articles (catid,content,title,keywords,isactive)  
SELECT 1,pendingarticles.content,pendingarticles.title,  
        pendingarticles.keywords,1  
FROM pendingarticles  
WHERE pendingarticles.id=1;  
DELETE FROM pendingarticles WHERE id=1; 

The extra set of parenthesis you provided is not necessary.

Comments

-1

I believe that the parentheses around the Select are not necessary.

http://dev.mysql.com/doc/refman/5.6/en/insert.html

START TRANSACTION; 
INSERT INTO articles (catid,content,title,keywords,isactive) 
SELECT 1, pendingarticles.content, pendingarticles.title, 
pendingarticles.keywords, 1 
FROM pendingarticles 
WHERE pendingarticles.id=1;
DELETE FROM pendingarticles WHERE id=1; 
COMMIT; 

3 Comments

i think you mean parenthesis () these are brackets []
@Dukeling and yet the image that is there says brackets are are these things []
@Woot4Moo "Parentheses ... (also called simply brackets ...". Bottom line is - you may not call them brackets, but that doesn't stop other people from being correct while calling them brackets.

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.