Mysql - set column value equal to id insertion?

Background:

I have a database table that for received_msgs

The table has two columns.

id, link_id

If the message is the first of them (based on criteria), then it link_idis equal to it id.

If it is a response to a message, it link_idis equal to the idmessage to which it replies.


Question:
is there any way in the original insert to set link_idthe same as id?

At the moment, I am doing an insertion and then doing another request, updating and setting link_idequalINSERT_ID

But I do not like to use two queries for it.

+3
source share
2 answers

AFTER INSERT.

NULL .

+1
INSERT into your_table (id, link_id) values (ID, ID);
0

Source: https://habr.com/ru/post/1776804/


All Articles