There is a request:

INSERT INTO orders (`date`, `dostavka_id`) VALUES (NOW(), $dostavka_id) 

In the orders table itself, besides date and dostavka_id , there is also a type . There is an info table with the same type . Actually the question is, how do I get the type out of the info table and write it in orders ?

I tried this:

 INSERT INTO orders (`date`, `dostavka_id`) VALUES (NOW(), $dostavka_id) LEFT JOIN info ON (info.type = orders.type) 
  • Not quite clear question. You need to insert the three date , dostavka_id and type fields so that the type taken from info and the other fields are set directly? Then you can try something like this: INSERT INTO orders (`date`, `dostavka_id`, `type`) SELECT NOW(), $dostavka_id, `type` FROM `orders` - BOPOH
  • I have two identical cells (type) in two different bases. When inserting INSERT INTO VALUES, I need to add another type from another database, using the same ID :) - user181354
  • I don’t understand anything (c). How and where do you want to insert this type ? "How to pull out the type from the info table and write it in orders" I showed ( INSERT INTO .. SELECT `type` FROM... ) But since this is not that, then at least you can give an example? Those. what is at the entrance, what should happen at the exit. - BOPOH

1 answer 1

 INSERT INTO orders (`date`, `dostavka_id`, `type`) VALUES (NOW(), $dostavka_id, (SELECT `type` FROM orders where --тут вставьте условие, с помощью которого выбирается нужный type из orders--));