开发者

whats wrong with this mysql insert query?

insert into tblcustomermachine
(
 select * from
 ((select vch_CustomerID  from tblcustomer where tblcustomer.vch_CustomerID='Cust00001' )
 union all
 (s开发者_Python百科elect Rate  from tblmachine))  as t );

that table contains 18 cols and this resultset also contains 18 rows yet it shows " Column count doesn't match value count at row 1" . why?


It looks like your table tblcustomermachine has more then the 1 column.

Like Simone answered, update your insert to INSERT INTO tblcustomermachine(col_1) SELECT ...

You may skip the column names during INSERT, however the SELECT needs to return the same amount of columns that the table holds.


AFAIK, you have to declare field name:

insert into tblcustomermachine (col_1, col_2, col_3, ... col_18) (
   select t.field1, t.field2, t.field3, ... t.field18 from (
      (select vch_CustomerID from tblcustomer where tblcustomer.vch_CustomerID='Cust00001') 
       union all (select Rate from tblmachine))
   as t
   );
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜