1

I tried this:

INSERT INTO event_log_tracker_table 
SELECT * FROM event_tracker_table WHERE eventid = '560'

However I get this error:

Error Code: 1136. Column count doesn't match value count at row 1

The columns match exactly the same except for one thing...

I added one more column (eventlogid) in event_log_tracker_table to be a primary key. How can I insert a row, from another table and have it add to a primary key in the new table?

Below is a structure of the tables.

event_log_tracker_table (24 columns)
-----------------------
eventlogid - PK
eventid - INT
//
//  22 other columns
//

event_tracker_table (23 columns)
-----------------------
eventid - PK
//
//  22 other columns
//

I have tried to do this:

INSERT INTO event_log_tracker_table 
SELECT null, * FROM event_tracker_table WHERE eventid = '560'
Arian Faurtosh
  • 17,987
  • 21
  • 77
  • 115

1 Answers1

2

As documented under SELECT Syntax:

  • Use of an unqualified * with other items in the select list may produce a parse error. To avoid this problem, use a qualified tbl_name.* reference

    SELECT AVG(score), t1.* FROM t1 ...
    

Therefore, instead of SELECT NULL, * you could should qualify the wildcard:

INSERT INTO event_log_tracker_table 
SELECT NULL, event_tracker_table.*
FROM   event_tracker_table
WHERE  eventid = '560'
eggyal
  • 122,705
  • 18
  • 212
  • 237