Jump to content

Column Count doesn't match with a "having" statement


The Little Guy

Recommended Posts

I need to use this code, to insert values that don't exist in a table. The issue that I am having, is my last query where I need to do an "insert into select from" using a "having". I need all fields where pid is null, but I don't want to insert pid into the "recurring" table. I need to select the column otherwise the having won't work. The error I am getting is:

ERROR 1136 (21S01): Column count doesn't match value count at row 1

 

I can't think of a solution to this problem, anyone have any suggestions?

 

drop temporary table if exists ap_purch;

create temporary table ap_purch (member_id int, product_id int);

insert into ap_purch (member_id, product_id) select member_id, product_id from purchases where product_id in(1,25,87,88,89,90,91,92) group by member_id, product_id;

insert into recurring (member_id, product_id, is_enabled, processor_id) select a.member_id, a.product_id, 1, 9, r.product_id pid from ap_purch a left join recurring r on(a.member_id = r.member_id and a.product_id = r.product_id) having pid is null;

 

The select return the results I want, it is just that the insert doesn't work.

Solved!

 

 

drop temporary table if exists ap_purch;
drop temporary table if exists need_ap;

create temporary table ap_purch (member_id int, product_id int);
create temporary table need_ap (member_id int, product_id int, is_enabled boolean, processor_id int, pid int);

insert into ap_purch (member_id, product_id) select member_id, product_id from purchases where product_id in(1,25,87,88,89,90,91,92) group by member_id, product_id;

insert into need_ap (member_id, product_id, is_enabled, processor_id, pid) select a.member_id, a.product_id, 1, 9, r.product_id pid from ap_purch a left join recurring r on(a.member_id = r.member_id and a.product_id = r.product_id) having pid is null;

insert into recurring (member_id, product_id, is_enabled, processor_id) select member_id, product_id, is_enabled, processor_id from need_ap;

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.