MySQL – Update query based on SELECT Query

In this tutorial, we will discuss MySQL – Update query based on SELECT Query where both Update and select queries are DML Data Manipulation Languages. where we deal with the data and we manipulate, add, update, or select and display the data as per our choice.

Update

Update Command

The update command is used for making changes in the data present in the table. Or we can say when we have to make certain changes in the data present in the table, Which might include editing the existing data, Making a new record, and adding it to the table, It might we deleting the existing data or just rearranging the data the way we want.

All of these tasks are dealing with data so it is called data manipulating Commands of DML commands so to make it clear as we use it only on data stored in the data table. And to manipulate the data we give conditioning where clause to identify the record uniquely for editing or making some changes.

to understand it and get a clear idea of what exactly the update is follow the example given below.

UPDATE orders
SET shipped = (SELECT shipped_date FROM shipments WHERE orders.order_id = shipments.order_id)
WHERE shipped IS NULL;

Here we are updating the table order and setting shipped with the data we want with the help of a select clause which is used for getting the data from the table simply for displaying the data.

Select Command

Select command simply deals with displaying the data and it is a data manipulating command which only deals with manipulation of Data here we are simpling selecting the data and displaying it to understand it looks at the example given below

Select * from table1;

The above query is used for displaying the whole data of the table where we can see how we can display the whole data and we even can provide certain filters to limit the data to be displayed on display.

 

Learn more at updating the data using the select command.

Also, visit MySQL Problems And Tutorials to learn more about MySQL and for learning about the solutions of different programming languages visit beta python for programing Solutions

Leave a Comment

%d bloggers like this: