Click here to Skip to main content
15,883,705 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
I have two tables with same and different fields . I want to merge the two table into one please give an easiest query to complete this process

SQL
INSERT INTO invoice (
      invoiceid
       )
  VALUES (
      (SELECT invoiceid

       FROM accountinginvoice where invoice_gid='s5678433;))


this is my query this work only for same fields i want to merge different fields
Posted

 
Share this answer
 
Comments
lekha g nair 24-Feb-15 23:28pm    
Am tries this but error occurred as Column count doesn't match value count at row 1
[no name] 24-Feb-15 23:33pm    
Missing any values ? chk the table ?
Try this:
SQL
INSERT INTO invoice (invoiceid)
SELECT invoiceid FROM accountinginvoice where invoice_gid='s5678433'
 
Share this answer
 
Comments
lekha g nair 24-Feb-15 23:32pm    
INSERT INTO invoice
SELECT invoiceid, customerid
FROM accountinginvoice where invoiceid='0380'

I am tried this but error occurred Column count doesn't match value count at row 1
Peter Leow 24-Feb-15 23:41pm    
The number of columns that you want to insert must tally with the number of columns that come from select.
I do not know your table structures, assuming invoiceid and customerid exist in invoice and accountinginvoice tables, then according to your latest code snippet, it should be:
INSERT INTO invoice (invoiceid, customerid)
SELECT invoiceid, customerid
FROM accountinginvoice where invoiceid='0380'

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