mysql query to move unique rows to temp table -
i want create query move every unique entry 1 table temporary table. created following query unique entrys:
select date, messagetype, zcampaignid, issenderpolicy, sender, recipient, policy, operator, country, znumber topcampaigns_hour group date, messagetype, zcampaignid, issenderpolicy, sender, recipient, policy, operator, country, znumber having count(*) = 1;
and returns lots of results:
/* affected rows: 0 found rows: 473 warnings: 0 duration 1 query: 0.000 sec. (+ 0.016 sec. network) */
however when put update cant seem tmp table updated:
update topcampaigns_hour_tmp b inner join ( select date, messagetype, zcampaignid, issenderpolicy, sender, recipient, policy, operator, country, znumber topcampaigns_hour group date, messagetype, zcampaignid, issenderpolicy, sender, recipient, policy, operator, country, znumber having count(*) = 1) set b.date=a.date, b.messagetype=a.messagetype, b.zcampaignid=a.zcampaignid, b.issenderpolicy=a.issenderpolicy, b.sender=a.sender, b.recipient=a.recipient, b.policy=a.policy, b.operator=a.operator, b.country=a.country, b.znumber=a.znumber;
which resulted in:
/* affected rows: 0 found rows: 0 warnings: 0 duration 1 query: 00:04:25 */
i tried number of things using:
update topcampaigns_hour_tmp join (select date, messagetype, zcampaignid, issenderpolicy, sender, recipient, policy, operator, country, znumber topcampaigns_hour group date, messagetype, zcampaignid, issenderpolicy, sender, recipient, policy, operator, country, znumber having count(*) = 1) set topcampaigns_hour_tmp.date=a.date, topcampaigns_hour_tmp.messagetype=a.messagetype, topcampaigns_hour_tmp.zcampaignid=a.zcampaignid, topcampaigns_hour_tmp.issenderpolicy=a.issenderpolicy, topcampaigns_hour_tmp.sender=a.sender, topcampaigns_hour_tmp.recipient=a.recipient, topcampaigns_hour_tmp.policy=a.policy, topcampaigns_hour_tmp.operator=a.operator, topcampaigns_hour_tmp.country=a.country, topcampaigns_hour_tmp.znumber=a.znumber;
again got:
/* affected rows: 0 found rows: 0 warnings: 0 duration 1 query: 00:03:42 */
the topcampaigns_hour_tmp table never seems updated.
what doing wrong?
a
if you're adding rows need insert
, , if you're adding rows query results need insert ... select
. try this:
insert topcampaigns_hour_tmp ( date, messagetype, zcampaignid, issenderpolicy, sender, recipient, policy, operator, country, znumber) select date, messagetype, zcampaignid, issenderpolicy, sender, recipient, policy, operator, country, znumber topcampaigns_hour group date, messagetype, zcampaignid, issenderpolicy, sender, recipient, policy, operator, country, znumber having count(*) = 1
Comments
Post a Comment