2011-02-08 32 views
1
insert into tblcustomermachine 
(
select * from 
((select vch_CustomerID from tblcustomer where tblcustomer.vch_CustomerID='Cust00001') 
union all 
(select Rate from tblmachine)) as t); 

該表包含18列,該結果集還包含18行,但它顯示「列計數與第1行的值計數不匹配」。爲什麼?這個mysql插入查詢有什麼不對嗎?

+0

resultset還包含18行。它必須在結果集中包含18列 – 2011-02-08 11:40:25

回答

1

它看起來像你的表tblcustomermachine有更多的則1列。

像西蒙回答,更新您的刀片,INSERT INTO tblcustomermachine(col_1) SELECT ...

期間INSERT您可以跳過列名,但是SELECT需要返回表所擁有的列相同。

0

據我所知,您必須聲明字段名:

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

列數不是一個穩定的列。它可能有所不同 – Even 2011-02-08 11:54:22