简体   繁体   中英

Update rows on to tables in mysql

I need to update the rows of two tables (song & words).

How can I do it using the same query? Here's my first update:

string query2 = "Update myproject.song set house_number = '" + first.Length + "';";

MySQL permits you to multiple tables as shown here: MySQL update syntax documentation

UPDATE song,artist SET song.title=a,artist.song_count=b
WHERE artist.id=song.artist_id;

In this example, song, and artist are the two tables with rows, title and song_count respectively. The WHERE clause ensures that this is being done based on your criteria

You wouldn't update two tables at the same time. Try updating song, then using the primary key of song to update the correct row in words.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM