Insert row question into table

May I know whether ANY mysql code can just we insert the data like row 1 until row 19 i put date as '2017-11-01' and then on row 20 until row 40 i put date as '2017-11-02' etc .. something like this.Capture.PNG
Dave ITnewbie ITAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
this is not possible for distinguish between the records.... as there is no unique identifier if you just having columns: Power State and date while all your records contain same values. when you update the records with values, you will all get the same values.

you need at least one unique identifier in this case.
Dave ITnewbie ITAuthor Commented:
If i add 1 more column put as Name .. so i can put the value like that?
Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
it's fine to have a unique field, so that we can update the values accordingly, but it would be good if you can tell us the "sequence" as well.

if the table is sorted alphabetically by a field (let's called it sortcol), then you can try:


    (@row_number:=@row_number + 1) idx, `Name`, `date`, sortcol
    yourtable,(SELECT @row_number:=0) AS t
ORDER by sortcol  

Update tmp set `date` = '2017-11-01' where idx <= 19;
Update tmp set `date` = '2017-11-02' where idx >= 20 and idx <= 40;

update yourtable a inner join tmp b
on a.`Name` = b.`Name`
set a.`date` = b.`date`;

select * from yourtable order by sortcol;

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
MySQL Server

From novice to tech pro — start learning today.