Answer the question
In order to leave comments, you need to log in
How to perform an INSERT with a subquery?
There are 2 tables: auto and parking_time
Need to INSERT into parking_time. The problem is that there is all the data except auto.id, but there is auto.car_number.
In theory, you need to execute an INSERT query with a SELECT subquery to get the car id. How to implement it correctly?
Answer the question
In order to leave comments, you need to log in
https://www.w3schools.com/sql/sql_insert_into_sele...
See the last example.
insert into parking_time (owner_id, auto_id, parker_id, place_id, begin_date, exp_date)
select :owner_id, a.id, :parker_id, :place_id, :begin_date, :exp_date
from auto a
where a.car_number = :car_number
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question