2011-02-08 3 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列を含める必要があります。 –

答えて

1

それは、tblcustomermachineが1列、より多くを持っているあなたのテーブルのように見えます。シモーネ同様

あなたはテーブルが保持する列の同じ量を返すために、INSERTの間しかしSELECTニーズに列名をスキップすることがありINSERT INTO tblcustomermachine(col_1) 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

colsは安定していません。それは変わるかもしれない – Even

関連する問題