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.

Link to comment
Share on other sites

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;

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.