oracle - SQL - Joining multiple tables? -
i'm trying join multiple tables create list of purchase orders total cost. have tried following select statement returns error of "'oa'.'aircraft_code' invalid identifier"
select al.airline_code “airline code”, po.purchase_order_no “order number”, ac.aircraft_code “aircraft code”, oa.aircraft_quantity “quantity of aircraft ordered”, sum(oa.aircraft_quantity * ac.aircraft_price) “order total” aircraft ac, airline al, ordered_aircraft oa, purchase_order po join airline al on po.airline_code = al.airline_code join aircraft ac on oa.aircraft_code = ac.aircraft_code join purchase_order po on oa.purchase_order_no = po.purchase_order_no group po.purchase_order_no order al.airline_code asc;
the database structure follows:
aircraft
name null? type ----------------------------------------- -------- ---------------------------- aircraft_code not null varchar2(5 char) aircraft_type not null varchar2(30 char) aircraft_price not null number(11,2)
airline
name null? type ----------------------------------------- -------- ---------------------------- airline_code not null varchar2(4 char) airline_name not null varchar2(20 char) airline_address not null varchar2(100 char) airline_city not null varchar2(20 char) airline_country not null varchar2(20 char)
ordered_aircraft;
name null? type ----------------------------------------- -------- ---------------------------- purchase_order_no not null number(3) aircraft_code not null varchar2(5 char) aircraft_quantity not null number(2)
purchase_order
name null? type ----------------------------------------- -------- ---------------------------- purchase_order_no not null number(3) airline_code varchar2(4 char) purchase_order_date not null date
any great. thank you.
take tables joining out of list after from:
select al.airline_code “airline code”, po.purchase_order_no “order number”, ac.aircraft_code “aircraft code”, oa.aircraft_quantity “quantity of aircraft ordered”, sum(oa.aircraft_quantity * ac.aircraft_price) “order total” ordered_aircraft oa /* , airline al, ordered_aircraft oa, purchase_order po */ <--- join purchase_order po on oa.purchase_order_no = po.purchase_order_no join airline al on po.airline_code = al.airline_code join aircraft ac on ac.aircraft_code = oa.aircraft_code group po.purchase_order_no order al.airline_code asc;
using comma-separated list of tables different join syntax. if using join there's no need reference them again.
Comments
Post a Comment