Hy Folks, Today we will learn how to insert a row after a specific row in MySqlWorkbench.We already know simple insert query to inserting the rows row in MySQL but lot's of peoples confused about how to insert a row in the middle of the rows or specific rows. In this post, I will cover your Doubts and Confusions and give you the best solution.
Task - You have DB and Table where 6 rows inserted and you have to insert new rows after the 3rd rows.
So Let's Complete the task and learn it.
I have made some points with the help of you can easily understand.
Note* Please do follow the Steps.
I have uploaded a video of it here. you can watch and easily understand. Click here
Step - 1
Open your MySql workbench or phpMyAdmin Tool. I have MySqlWorkbench so I will demonstrate it to you.
Step - 2
First, create a Database and table I hope you have already created. I have created DB name is test and table name is demo_table. I have inserted 6 rows in the table as shown in the image below.
Step - 3
As per the above task we have to insert a new row after the third row ( column name Id ). let's think about how can we do it.
Logic
So let's write the query for it.
UPDATE test.demo_table set id = id +1 WHERE id >= 4 order by id desc;
After executing this query you will see all those ids has been incremented which was greater than 3. which id was 4 before. now that id has been a change.
OUTPUT -
Video -
Step - 4
Now we have a row where we can insert the new row after the 3rd row which id will be 4. so just we have to insert a new row after the 3rd row.
So let's write the Insert Query
INSERT INTO test.demo_table (id,name,status,demo_tablecol) VALUE (' 4' , ' new entry for 4th row ' , 0,' ' );
OUTPUT -
You can see in the above image where we have successfully inserted a new row and its value.
Finally, we have completed the Task and learned how can we insert a row after a specific row.
I hope you understood this and like this article. if you like it so, please give feedback in the comment section.
If any mistakes I made here, so please let me know and improve me.
If you have any query, feel free to ask me ЁЯШК
Recommended Post
- How to fix Warning: MySQL server has gone away error php
- How to Get All Google play store apps List using PHP Scraper?
- How to pass a variable from the command line using PHP?
- How to Submit Registration and Login Form in PHP?
- Introduction PHP
- how to declare variables in PHP?
- What things you need to install PHP?
- How to get meta tags in 2 easy way in PHP
- How to Encode and Decode Strings with Base64 in JavaScript examples
- How to Reset DropDownList Selection Using jQuery?
- Create dynamic drop-down list option with JavaScript and jQuery
- Onclick show and hide div using JQuery with examples
Post a Comment
Please do not enter any spam link in the comment section.