If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Syntax error for insert

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-05-07, 11:48
screenmates screenmates is offline
Registered User
 
Join Date: Jul 2005
Posts: 63
Syntax error for insert

Hi All,

What's wrong with the following SQL:

INSERT INTO user_info ( ID, Title, Notes ) VALUES ( SELECT ID, Title, Notes FROM user WHERE ID = 129)

Error:
SQLSTATE[42000]: Syntax error or access violation: 1064 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 'SELECT ID, Title, Notes FROM user WHERE ID = 129)' at line 2

user and user_info have a one-to-one relationship (innodb/myisam) for full-text searchability.

TIA
Reply With Quote
  #2 (permalink)  
Old 05-05-07, 12:31
shammat shammat is offline
Registered User
 
Join Date: Nov 2003
Posts: 2,408
INSERT INTO user_info ( ID, Title, Notes )
SELECT ID, Title, Notes
FROM user WHERE ID = 129;

The VALUES is not needed when using a SELECT
Reply With Quote
  #3 (permalink)  
Old 05-05-07, 12:39
screenmates screenmates is offline
Registered User
 
Join Date: Jul 2005
Posts: 63
It worked!!

Thanks much!
Reply With Quote
  #4 (permalink)  
Old 05-05-07, 13:16
shammat shammat is offline
Registered User
 
Join Date: Nov 2003
Posts: 2,408
Btw: next time simply read the manual
http://dev.mysql.com/doc/refman/5.0/en/insert.html
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On