sql - Joining multiple tables in MySQL: "Unknown column" -
i'm running error simple join
in mysql. missing obvious?
select stop_times.stop_sequence stop_times inner join stops on stop_times.stop_id = stops.stop_id inner join trips on stop_times.trip_id = trips.trip_id stops.stop_code = :stopcode;
where :stopcode
parameter bound via pdo.
the error i'm getting is: sqlstate[42s22]: column not found: 1054 unknown column 'stop_times.trip_id' in 'on clause''
the database schema these 3 tables are:
stop_times ---------- trip_id varchar(23) not null -- pk arrival_time time not null departure_time time not null stop_id int(10) unsigned not null -- pk stop_sequence int(10) unsigned not null -- pk stops ----- stop_id int(10) unsigned not null -- pk stop_code int(5) unsigned null stop_name varchar(53) not null stop_lat decimal(8, 6) not null stop_lon decimal(9, 6) not null stop_url varchar(66) null trips ----- route_id int(8) unsigned not null service_id varchar(6) not null trip_id varchar(23) not null -- pk trip_headsign varchar(255) not null
i've tried using aliases didn't work. running query in microsoft access works, sql produced has brackets around join statements though.
why query not working?
are using ticks (`` `)in actual query escape table / column names, stripping them out of question? i'm guessing yes, because gave formatting issues since stack overflow uses them escape code blocks...
my guess meant write:
inner join `trips` on `stop_times`.`trip_id` = `trips`.`trip_id`
but instead, wrote:
inner join `trips` on `stop_times.trip_id` = `trips`.`trip_id`
since you're missing pair of ticks, gets treated single column name, giving following error:
unknown column 'stop_times.trip_id' in 'on clause': select stop_times.stop_sequence stop_times inner join stops on stop_times.stop_id = stops.stop_id inner join trips on
stop_times.trip_id
= trips.trip_id stops.stop_code = 1
Comments
Post a Comment