I am using a select statement with a join to try and insert a column into a mySQL database table.
My code:
insert into trips_last_arrival_time(start_time)
select min_arrival_time.start_time
from min_arrival_time
inner join trips_last_arrival_time
on min_arrival_time.trip_id = trips_last_arrival_time.trip_id;
I am getting :
[Err] 1364 - Field 'trip_id' doesn't have a default value
trip_id is the primary key of both tables.
The start_time column is blank, not filled with nulls.
I’ve tried an UPDATE clause too
update trips_last_arrival_time
set trips_last_arrival_time.start_time = (
select start_time from min_arrival_time )
where exists(
select trip_id from trips_last_arrival_time
where trips_last_arrival_time.trip_id = min_arrival_time.trip_id)
And there’s a column trip_id in the table min_arrival_time (in fact it’s the primary key of both tables!)
But this UPDATE clause gives me:
[Err] 1054 - Unknown column 'min_arrival_time.trip_id' in 'where clause'
What am I missing?
You are trying to insert on an existing row (it exists because you have tried to SELECT it). Regardless of whether
trip_idhas a default value, this is not the correct operation. You need to do an UPDATE.For your update, I’m pretty sure you need to do this: