Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mysql Query Issue - Insert into select join

Tags:

join

mysql

I am trying to make an query on my database, I want to move all the rows that have eventcodes.PRIORITY=1 and g052013.WCODE=eventcodes.WCODE, as you can see I copy all the rows from the last month to the new month. the error I get is :
#1136 - Column count doesn't match value count at row 1
and I have the same number of cols in the tables.
What I am doing wrong here?
Here is my query :

insert into g062013
select g052013.pnumber,g052013.id,
g052013.Ccode,
g052013.WCODE,
g052013.ndate,
g052013.TIMECALL,
g052013.EventHandling,
g052013.Endtimecare,
g052013.User,
g052013.TIMEARRIAVAL,
g052013.FREEDATA,
g052013.sendtime from
g052013 RIGHT JOIN eventcodes ON g052013.WCODE=eventcodes.WCODE AND   eventcodes.PRIORITY='1' 
WHERE gyoman052013.EventHandling!=2
like image 565
Ofir Attia Avatar asked Mar 24 '26 12:03

Ofir Attia


1 Answers

When you are using implicit syntax of INSERT statement wherein you did not specify the column names, the number of values must match with the number of columns in the table otherwise wise you'll receive an error message

#1136 - Column count doesn't match value count at row 1

To fix this problem, you need to explicitly define the column names on where the values will be saved. Ex,

INSERT INTO tableName(col1, col2, col3)
SELECT val1, val2, val3
FROM tableName
like image 164
John Woo Avatar answered Mar 27 '26 05:03

John Woo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!