Reputation: 461
I have a table with different fields like this:
+----+-------------------+------+--------+
| id | Name | phone| Date |
+----+-------------------+------+--------+
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
+----+-------------------+------+--------+
I entered a number of phone number lines like:
+----+-------------------+------+--------+
| id | Name | phone| Date |
+----+-------------------+------+--------+
| 1 | |563824| |
| 2 | |525225| |
| 3 | |546542| |
| 4 | |464625| |
| 5 | |654525| |
| 6 | |849842| |
| 7 | |654446| |
+----+-------------------+------+--------+
Ok now I have phone data and Id of rows. Now My problem what I try to do I need to insert multiple names in Column Name at one time. Insert this names like update to multiple rows at one time but between specific id.
example I need to update rows from Id 3 to 5 to can insert names:
+----+-------------------+------+--------+
| id | Name | phone| Date |
+----+-------------------+------+--------+
| 1 | |563824| |
| 2 | |525225| |
| 3 | Ali |546542| |
| 4 | Ahmad |464625| |
| 5 | Marwan |654525| |
| 6 | |849842| |
| 7 | |654446| |
+----+-------------------+------+--------+
How I can do that? Any idea to do that ?I need to insert data from MySQL (Run SQL query/queries on table)
The names are in brackets because I am converting the data from an excel file to the Mr. Data Converter example: ('Marwan'),('Ali'),('Jake').
Upvotes: 0
Views: 1435
Reputation: 1189
You can just add WHERE condition
to specify which row you want to update.
Also, since the rows are already existing, you have to use UPDATE
instead of INSERT INTO
.
Example:
UPDATE employ SET name = 'Ali' WHERE id >= 3 and id <= 5;
This will update the name of all the rows with id between 3 and 5.
If you want to update multiple rows with specific ids, you can try this:
UPDATE employ SET name = 'Ali' WHERE id IN (3,4,5,8,11);
Upvotes: 1