I'm new to SQL, I'm interested in, is it possible to execute an INSERT construct in a single query after a SELECT ?

  • 2
    and what do you actually want to achieve? - splash58

2 answers 2

In almost all modern databases, you can use the INSERT ... SELECT ... , which allows you to insert into the table the results of a selection with the SELECT

 INSERT INTO tab1 SELECT * FROM tab2 
  • This is yes, but I need to implement a SELECT type construct tab1 FROM table UNION INSERT INTO - Filipp Mustang
  • @FilippMustang, then look towards the triggers - the stored functions that trigger on each insertion or update of data. - cheops 5:43 pm
  • 3
    @FilippMustang And what do you think would have to execute the select union insert query if it were possible? - Mike
  • one
    There are things like sql injections. There are no two possible requests. The ultimate goal is to change the data in the table from a beginner's query with a SELECT. - Filipp Mustang

for example, we have a query like
"SELECT * FROM news WHERE id_news = $id"
we can transfer there that as like
666;INSERT INTO user(username, password) VALUES ('i', '777');
and get two teams
SELECT * FROM news WHERE id_news = 666; INSERT INTO user(username, password) VALUES ('i', '777');

  • This approach worked until about 2008. There are usually restrictions; you can only perform one request at a time. - Filipp Mustang