Click here to Skip to main content
15,794,593 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I am currecntly working with HeidiSQL, and my problem is that I cannot figure out how to get data from one table, and insert it into a different table that has the same column names...
My query so far is:
SQL
INSERT INTO tbltransactions (TransactionID, TransactionDate, PaymentMethod, CashTendered, CustomerID)
SELECT (trans_id, date_time, payment_method, cash_tendered, customer_id) FROM shop_transactions

Just wondering whether anyone can see the error I am making here as I can't! The error message that appears is:
SQL Error (1241): Operand should contain 1 column(s)
Thanks guys,
Tom.
Posted
Updated 28-Sep-11 0:18am
v2

Try removing the () around the columns :
SQL
INSERT INTO tbltransactions (TransactionID, TransactionDate, PaymentMethod, CashTendered, CustomerID)
SELECT trans_id, date_time, payment_method, cash_tendered, customer_id FROM shop_transactions
 
Share this answer
 
Comments
Reiss 28-Sep-11 5:31am    
I was going to suggest what happens when just the select is executed, but I believe that this will resolve the issue
Mehdi Gholam 28-Sep-11 5:40am    
Cheers
Try removing brackets.
SQL
INSERT INTO tbltransactions (TransactionID, TransactionDate, PaymentMethod, CashTendered, CustomerID)
SELECT trans_id, date_time, payment_method, cash_tendered, customer_id FROM shop_transactions
 
Share this answer
 
Insert Into tableName1 (column1 (datatype),column2(datatype)) values(select column1, column2 from tableanme2)
 
Share this answer
 
I don't believe it, it worked! Such a minor error aswell, been scanning through it for ages to find the fix!

Thanks Mehdi,
Tom.
 
Share this answer
 
Comments
André Kraak 28-Sep-11 5:31am    
If you have a question about or comment on the given solution use the "Have a Question or Comment?" option beneath the solution. When using this option the person who gave the solution gets an e-mail message and knows you placed a comment and can respond if he/she wants.

Please move the content of this solution to the solution you are commenting on and remove the solution. Thank you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900