Updating a table in mysql

What makes me especially nervous is when the data is coming from another table.

This is definitely not the time for an unexpected result!

Please familiarize yourself with it if you haven't done so.

My SQL can use either standard or non-standard (non ANSI standard) SQL syntax format to perform cross-table update.

Note that the SQL needs to end with semi-colon if you have multiple queries in the query window.

Most of the queries in the tutorials need Northwind My SQL database, you can download the database script on this page.

Instead, updates use table joins to connect related rows to each other.

If that source happens to be other tables within the same database, then My SQL has got you covered. SELECT” statement, which selects the fields from one table and inserts them into another.

For instance, the following statement will take all the records from table1 and insert them into table2: As the name suggests, I’d like to store the most expensive rentals in their own table. Using the INSERT…SELECT statement, we can populate all of the fields except for the id, which is an AUTO_INCREMENT type: Since the primary key is not being inserted in the above example there is nothing stopping duplicate records from being created. Of course you will have to supply the id value as well or the record will never be a duplicate!

We are going to update column Description and Picture in table Categories_Test by using data in table Categories, based on data in the common column Category ID.

Table: Categories Table: Categories_Test Use the following script to create the categories_test table in My SQL Northwind database.

Leave a Reply