mysql - Update query does not update few rows -


with following table:

"id"    "type"  "parent"    "country"   "votes" "percent" "1"     "1"     "0"         "us"        "0"     "0"//appears 0, should 12 "2"     "2"     "1"         "us"        "0"     "0"//appears 0, should 8 "3"     "3"     "2"         "us"        "4"     "0" "7"     "3"     "2"         "us"        "4"     "0" "19"    "3"     "1"         "us"        "4"     "0" "4183"  "10"    "3"         "us"        "2"     "0" "4184"  "10"    "3"         "us"        "2"     "0" "4185"  "10"    "7"         "us"        "2"     "0" "4186"  "10"    "7"         "us"        "2"     "0" "4187"  "10"    "19"        "us"        "2"     "0" "4188"  "10"    "19"        "us"        "2"     "0" 

why row id 1 , row id 2 appear 0 when run following query update totals?

update  likesd         inner join         (             select  parent, country, sum(votes) totalvotes                likesd             group   parent         ) b on a.id = b.parent , a.country = b.country set     a.votes = b.totalvotes; select * likesd; 

when do:

select  parent, country, sum(votes) totalvotes                likesd             group   parent; 

i can see rows in result, top 2 don't update.

am going wrong sql? how set right? also, u see problems in sql i'm using?

you should put country in group clause checking country while updating.

update  likesd         inner join         (             select  parent, country, sum(votes) totalvotes                likesd             group   parent, country         ) b on a.id = b.parent , a.country = b.country set     a.votes = b.totalvotes; select * likesd; 

edit can try following update statement in case of unexpected result -

update likesd    set voltes = (select sum(votes)                    likesd b                   b.parent = a.id                     , b.country = a.country) 

Comments

Popular posts from this blog

.htaccess - First slash is removed after domain when entering a webpage in the browser -

Automatically create pages in phpfox -

c# - Farseer ContactListener is not working -