How to insert last ID field from another table?

Make this INSERT:
INSERT INTO galaxy (name, type, FLOAT diametr, mass, discovery_date, birth_date FLOAT, astronomical_object ) VALUES (...)


in the "astronomical_object" you want to put the last ID from the same table
March 19th 20 at 09:15
2 answers
March 19th 20 at 09:17
Solution
INSERT INTO galaxy (name, type, FLOAT diametr, mass, discovery_date, birth_date FLOAT, 
 astronomical_object ) 
VALUES (..., (SELECT MAX('id') FROM astronomical_object))

Digression:

Last ID if you don't keep trigger, you will not be able to find. Since strings are not stored in the order received.
March 19th 20 at 09:19
SELECT `id`
FROM `tbl2`
ORDER BY `id` DESC
LIMIT 1
how to insert in the query - wallace79 commented on March 19th 20 at 09:22
@wallace79,
INSERT INTO galaxy (name, type, FLOAT diametr, mass, discovery_date, birth_date FLOAT, astronomical_object ) VALUES (..., (
 SELECT `id`
 FROM `tbl2`
 ORDER BY `id` DESC
 LIMIT 1
))
- Shakira_Goyet commented on March 19th 20 at 09:25

Find more questions by tags MariaDBSQLMySQL