![]() ![]() UPDATE asset_register SET crewID = newCrewData Īny help would be greatly appreciated, there is probably a better way to do this and a nudge in the right direction would be great. In the SET clause, you can set the column you wish to update, and you can also JOIN the two tables based on any predicate, I used c1.SeatingID c2.SeatingID AND c1.BusID c2.BusID, but you can choose what is suitable for your needs. Update column based on another column using WHERE clause Here’s the SQL query to update firstname column based on value of id columns using WHERE clause. SET newCrewData = (SELECT id FROM crews WHERE crewName = crewNameFromRegister) There are two ways to update column based on value of another column using WHERE clause and using CASE statement. SET crewNameFromRegister = (SELECT crewID FROM asset_register WHERE id = currentRow) Covering Your Tracks Extra MySQL Notes Second Order SQL Injections. MyUpdateLoop: WHILE (currentRow < rowCount) DO Language / Database Stacked Query Support Table About MySQL and PHP Stacked SQL. SET rowCount=(SELECT COUNT(*) FROM asset_register) So far i have the following but it updated the value of team to 'NULL' instead of the teamId. I thought that a stored procedure would be the way to go. The INSERT OR UPDATE command is an extension of the INSERT command, with these differences. There are nearly the same no of teams as users (~500) and I need to write a query or Stored Procedure to update all of them. You can import the new data into another table (table2). The problem lies in updating all the data in the asset_register table which was imported from excel. There is a MySQL statement where you can copy data from one table to another table of different table structures. The problem is that I want to create a team table and the reference the teamId in the asset_register table.ĭoes that make sense? Instead of storing the actual team name i want a foreign key to the teams table. The asset_register contains the following cols id INT, I have imported an excel document into MySQL to tidy up and make better use of the data but I am having problems running an update. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |