Ali Gangji
Ali Gangji

Reputation: 1501

What is wrong with this update query? I get "no records changed"

UPDATE sb_reviews 
SET clients_id=(SELECT clients_id 
                FROM sb_users 
                WHERE id=sb_reviews.users_id)

sb_reviews is a table with a users_id and and a newly created clients_id. I'm trying to grab the clients_id from the sb_users table and put it into the sb_reviews table where sb_users.id=sb_reviews.users_id

This query does not work though, I get no records changed.

Upvotes: 1

Views: 276

Answers (1)

Bohemian
Bohemian

Reputation: 425258

There is nothing wrong with your query.

In mysql, if the update has no effect (ie the value in the column isn't changing), it reports as not an update.

If you have already run this, you'll get "no records changed" message every run thereafter (unless data in the second table changes, of course).

Upvotes: 4

Related Questions