The Little Guy Posted October 19, 2011 Share Posted October 19, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/249411-column-count-doesnt-match-with-a-having-statement/ Share on other sites More sharing options...
The Little Guy Posted October 19, 2011 Author Share Posted October 19, 2011 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; Quote Link to comment https://forums.phpfreaks.com/topic/249411-column-count-doesnt-match-with-a-having-statement/#findComment-1280595 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.