Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mysql duplicate rows (ignore id + timestamp) without naming all other columns in the query?

I have tried to make this question concise in the title.

There are many answers to similar questions, but all involve naming every column in the table in the query.

What I want is a query to show me duplicate rows, but to ignore one or two columns, and I would like to be able to do it like shown in this post Return duplicate records, but without having to explicitly name every column in the table.

Is it possible?

like image 330
Keith Avatar asked Sep 10 '25 23:09

Keith


1 Answers

Note: Being that this is the top google result for 'workbench how to duplicate a row' I feel inclined to provide an answer for that question. If a moderator feels this is inappropriate; feel free to help resolve the inappropriation.

  1. Select all columns (or your target columns) from a single table, without joins or anything else that restricts in-editor inserts.

    Eg: SELECT * FROM mytable ORDER BY id DESC

  2. right-click on the row you want to copy, Copy Row

  3. Go to the bottom of the select results, end, there should be a line with all null's

  4. right-click on the null'ed row, Paste Row

    Don't forget to nullify, or set to be the default, any columns you want to keep; like the primary index/id, or any unique constrained columns!

  5. To insert your duplicated row use the Apply button on the lower right.

Workbench will open a dialog and show your the generated insert statements and offer to execute them for you. Permitting there are no errors you have just duplicated a row!

Run your select statement again to see your results.

like image 106
ThorSummoner Avatar answered Sep 12 '25 13:09

ThorSummoner