Today, We want to share with you mysql update statement.In this post we will show you delete query in mysqli, hear for mysqli updates multiple rows from (select) we will give you demo and example for implement.In this post, we will learn about Updateing Data in MySQL Using PHP with an example.
PHP MySQL Update Statement
UPDATE MySQL command is used to modify rows in a table. also i learn to Insert into a MySQL table or update if exists.
MySQL Update Command Syntax
UPDATE `table_name` SET `column_name` = `new_value' [WHERE condition];
UPDATE table SET column1 = expression1, column2 = expression2, ... [WHERE conditions];
Example – Update single column
UPDATE players SET product_name = 'Jignesh' WHERE player_id = 5000;
This MySQL UPDATE example would update the product_name to ‘Jignesh’ in the players table where the player_id is 5000.
Example – Update multiple columns
UPDATE players SET state = 'Rajkot', player_rep = 32 WHERE player_id > 100;
This MySQL UPDATE statement example would update the state to ‘Rajkot’ and the player_rep to 32 where the player_id is greater than 100
Example – Update table with data from another table
UPDATE players SET country = (SELECT country FROM teams WHERE teams.team_name = players.player_name) WHERE player_id > 1998;
This UPDATE example would update only the players table for all records where the player_id is greater than 1998. When the team_name from the teams table matches the player_name from the players table, the country from the teams table would be copied to the country field in the players table.
Example – Update multiple Tables
UPDATE players, teams SET players.country = teams.country WHERE players.player_id = teams.team_id;
This MySQL UPDATE statement example would update the country field in the players table to the country from the teams table where the player_id matches the team_id.
Updating Database Table Data
index.php
I hope you get an idea about sql set variable.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.