skip to Main Content

I has a mysql table with 2 int columns. The first column is auto_increment. Then, I want to insert whether a certain value or the value of the first column to the 2rd column.
For example

insert into tab(id,keyy) values (null, id);

I want this statement to insert a row with the id being the current ai number and the keyy the same as the id. Is there any simple way to do that?
Thank in advance.

2

Answers


  1. Chosen as BEST ANSWER

    I have had a problem. I has a table storing "label" and its "labelId", it also has a primary auto increment column called "rowId". When update label, I don't update the row but add a new row with that labelId and new label text. When add new label, I also insert new row and just input the label text, and the labelId should get the value of the current rowId. That's it when adding new label. I have thought that there's a simple solution for this. Thank for reading.


  2. To sort the rows in your MySQL table by the score in the mark column, showing the highest scores first, you can use the ORDER BY clause. To sort from highest to lowest, use DESC.

    SELECT * FROM your_table_name
    ORDER BY mark DESC;

    If you only want to see the top n rows with the highest scores, you can add the LIMIT clause

    SELECT * FROM your_table_name
    ORDER BY mark DESC
    LIMIT n;

    Replace n with the number of rows you want to retrieve. This will show the top n rows with the highest scores.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search