Thursday 15 July 2010

mysql - select from table and update another table SQL -



mysql - select from table and update another table SQL -

i'm trying 'business_id' , 'rating' table 'reviews' 'review_id' $approvereviewid

and update 'rating' in 'business_details' retrieved rating 'reviews' 'business_id' equal retrieved.

i have these 2 queries,

select business_id, rating reviews review_id = '$approvereviewid'; update business_details set rating = rating + $rating business_id = '$businessid';

is there way bring together these queries one?

yes, can utilize update-join syntax:

update business_details bd bring together reviews r on bd.business_id = r.business_id set bd.rating = bd.rating + r.rating r.review_id = '$approvereviewid'

mysql sql sql-update

No comments:

Post a Comment